table of Contents
Foreword
Wrote a .Net MVC personal notes, but not MarkDown, a pain, garden does not support previous blog articles turn MarkDown old, after a time to see if we can sort out, this time to open a new MarkDown of
Master Pages node
Write footer inside the master page
<footer>
@RenderSection("Footer")
</footer>
Then write in the sub-pages
@section Footer{
<h3>大家好,我是脚</h3>
}
So that it can handle the content of the page into the node position of the master page
Controller of the data to the View mode
ViewBag and share data ViewData
public ActionResult Index () {
ViewBag.UserName = "小李飞刀";
ViewData["UserName"] = "陆小凤";
TempData["UserName"] = "楚留香"; //临时数据
User model = new User { UserName = "谢晓峰" };
return View (model); //这行代码其实就相当于ViewData.Model=model
}
View Code
@{
ViewBag.Title = "Index";
}
<div>@ViewBag.UserName </div>
<div>@ViewData["UserName"] </div>
<div>@TempData["UserName"] </div>
<div>@Model.UserName</div>
The result is:
Lu Xiaofeng
Lu Xiaofeng
Chu Liu Xiang
Xie Xiaofeng
The reason is that [are] ViewDataDictionary type ViewData and ViewBag on nature, and the data shared between the two, but offers a different syntax mode of operation only. So "Lu Xiao Feng" covers the original value of the "Romantic Swordsman."
TempData used once data is deleted immediately after
As for Model, which can be used directly in the view @ Model.username for use, but you will find no prompt, this is because the compiler can not obtain Model type at compile time, if you want to be prompted to do so, in view of the above @model is written on the type of user
@model User