return View()相關簡介
在asp.net mvc中返回View時使用的是ViewResult,它繼承自ViewResultBase 同時它還有個兄弟PartialViewResult。一個用於返回整體,另一個返回局部(HTML)
使用相關
1、控制器書寫:除最后改為 “return PartialView()” 其余無差別
2、視圖書寫:@Html.Partial() 具有四個重載。根據情況選用
@Html.Partial("CustomerListControl") 當這樣寫的時候查詢所有文件名為 "CustomerListControl" 的文件,取第一個(按照字母升序排列)嵌套
@Html.Partial("CustomerListControl"); @*模糊查詢web內指定文件,同名按照后綴首字母升序排列*@
@Html.Partial("/Views/Home/ViewUserControl.ascx"); @*指定 路徑/文件*@
@Html.Partial("CustomerListControl", @Model);
@Html.Partial("CustomerListControl",ViewDataDictionary);@*ViewDataDictionary ViewData字典*@
@Html.Partial("CustomerListControl", @Model, ViewDataDictionary);
原文鏈接:http://www.cnblogs.com/Z-onee/p/6354516.html