ASP.NET MVC 分部页 PartialViewResult
2015-10-13 14:40
543 查看
PartialViewResult返回的也是一个页面,可以使用@Html.Partial加载这个部分页面,需要多次使用的时候可以用到他
加载部分页面
@Html.Partial("_pxcx", Model)
分页的时候其实就是改变的中间这一块,可以用ajax请求_pxcx,返回的是html在用js这返回的html加载到需要的地方就可以了
加载方式
@RenderPage()
但它不能使用 原来视图的 Model 和 ViewData ,只能通过参数来传递。
分部视图接收数据通过Page
@Html.Partial()
用于将分部视图渲染为字符串
@Html.Partial("_PartialPage1",model,ViewData)直接返回MvcHtmlString填充
Razor子视图里使用 ViewBag 来获取传递的数据
传递强类型到部分视图
_childPartial.cshtml
@RenderPartial()
http://www.cnblogs.com/raohuagang/p/3740353.html
public PartialViewResult _pxcx(string polName, string podName, string carrCode, string lineName, int page = 1) { int total = 0; var list = _Price_InfoManagement.GetDTO_PRICELCL_List(polName, podName, carrCode, "", "", lineName, "", page, pageSize, out total); ViewBag.Pager = PagerHelper.CreatePagerByAjax(page, pageSize, total, "lcl.priceQuery", false, lang == "CN"); return PartialView(list);//传入集合aps.net会解析好,然后返回一个页面html }
@model List<GTDesk.Domain.MainModule.Entities.DTO.DTO_C_PRICE> <table width="100%" border="0" class="lcl-table tac"> <tr id="thead"> <th scope="col">@ViewData["起始港"]</th> <th scope="col">@ViewData["目的港"]</th> <th scope="col">@ViewData["船公司"]</th> <th scope="col">@ViewData["船期"]</th> <th scope="col">@ViewData["航程"]</th> <th scope="col">@ViewData["中转港"]</th> <th scope="col">20GP</th> <th scope="col">40GP</th> <th scope="col">40HQ</th> <th scope="col">@ViewData["附加费"]</th> <th scope="col">@ViewData["有效日期"]</th> <th scope="col">@ViewData["Key_BookOnline"]</th> </tr> @if (Model != null && Model.Any()) { foreach (var item in Model) { <tr> <td>@item.POL_NAME_EN</td> <td>@item.POD_NAME_EN</td> <td>@item.CARR_CODE</td> <td>@item.ETD </td> <td>@item.TRANSIT_TIME</td> <td>@(string.IsNullOrEmpty(item.POT_NAME_EN) ? "直达" : item.POT_NAME_EN)</td> <td> <p class="wz2">@(item.PR_PRICE_20.HasValue?item.PR_PRICE_20.Value.ToString("00"):"")</p></td> <td><p class="wz2">@(item.PR_PRICE_40.HasValue?item.PR_PRICE_40.Value.ToString("00"):"")</p></td> <td><p class="wz2">@(item.PR_PRICE_40HQ.HasValue?item.PR_PRICE_40HQ.Value.ToString("00"):"")</p></td>
加载部分页面
@Html.Partial("_pxcx", Model)
分页的时候其实就是改变的中间这一块,可以用ajax请求_pxcx,返回的是html在用js这返回的html加载到需要的地方就可以了
//拼箱 var lcl = { //运价查询 priceQuery: function (index) { var polName = $("#POL_NAME_EN").combogrid('getValue'); var lineName = $("#LineId").combobox('getValue'); var podName = $('#POD_NAME_EN').combogrid('getValue'); var carrCode = $('#CARR_CODE').combogrid('getValue'); $.post('/home/_pxcx', { polName: polName, podName: podName, carrCode: carrCode, lineName: lineName, week: '', boxType: '', page: index }, function (data) { $('#price_box').html(data); }); } };所以用zazor在后台组织数据返回的页面,也是可以实现ajax分页的
加载方式
@RenderPage()
但它不能使用 原来视图的 Model 和 ViewData ,只能通过参数来传递。
1 @RenderPage("~/Shared/Component/Dialog.cshtml", new { title = "Hello world!", content="Nani" })
分部视图接收数据通过Page
1 <div id="dialog" title="@Page.title" style="display: none;"> 2 <p> 3 @Page.title 4 </p> 5 </div>
@Html.Partial()
用于将分部视图渲染为字符串
@Html.Partial("_PartialPage1",model,ViewData)直接返回MvcHtmlString填充
1 @Html.Partial("Component/Dialog", null, new ViewDataDictionary { { "title", "Hello world!" }, { "content", "Nani?" } })
Razor子视图里使用 ViewBag 来获取传递的数据
1 <div id="dialog" title="@ViewBag.title" style="display: none;"> 2 <p> 3 @ViewBag.content 4 </p> 5 </div>
传递强类型到部分视图
1 @{ 2 var args = new Dictionary<string,string>(); 3 args["redirectController"] = "Admin"; 4 args["redirectAction"] = "User"; 5 } 6 @Html.Partial("_childPartial",args)
_childPartial.cshtml
1 @model Dictionary<string,string> 2 <div>@Model["redirectController"]</div> 3 <div>@Model["redirectAction"]</div>
@RenderPartial()
http://www.cnblogs.com/raohuagang/p/3740353.html
相关文章推荐
- asp.net5中用户认证与授权(2)
- asp.net5中的用户认证与授权(1)
- 最简实例演示asp.net5中用户认证和授权(2)
- ASP.NET MVC下的异步Action的定义和执行原理
- ASP.NET动态网站制作(11)-- JQ(3)
- 最简实例演示asp.net5中用户认证和授权(1)
- ASP.NET MVC的四种验证编程方式
- ASP.Net MVC开发基础学习笔记(1):走向MVC模式
- ASP.Net MVC 给母版页视图传递数据
- 图文详解远程部署ASP.NET MVC 5项目 [转载]
- ASP.NET书籍信息录入实现代码
- ASP.NET购物车实现过程详解
- asp.net sql server错误:Timeout expired. The timeout period elapsed prior to completion of the operatio
- ASP基础入门第八篇(ASP内建对象Application和Session)
- ASP基础入门第七篇(ASP内建对象Response)
- ASP.NET MVC(4)
- ASP.NET MVC与WebForm对比
- ASP.NET连接数据库配置文件
- ARM assembler in Raspberry Pi – Chapter 3
- ARM assembler in Raspberry Pi – Chapter 1