ASP.NET MVC 分部页 PartialViewResult



PartialViewResult返回的也是一个页面,可以使用@Html.Partial加载这个部分页面,需要多次使用的时候可以用到他

[csharp]  view plain  copy
  1. public PartialViewResult _pxcx(string polName, string podName, string carrCode, string lineName, int page = 1)  
  2.        {  
  3.            int total = 0;  
  4.            var list = _Price_InfoManagement.GetDTO_PRICELCL_List(polName, podName, carrCode, """", lineName, "", page, pageSize, out total);  
  5.            ViewBag.Pager = PagerHelper.CreatePagerByAjax(page, pageSize, total, "lcl.priceQuery"false, lang == "CN");  
  6.            return PartialView(list);//传入集合aps.net会解析好,然后返回一个页面html  
  7.        }  

[html]  view plain  copy
  1. @model List<GTDesk.Domain.MainModule.Entities.DTO.DTO_C_PRICE>    
  2.  <table width="100%" border="0" class="lcl-table tac">  
  3.      <tr id="thead">  
  4.          <th scope="col">@ViewData["起始港"]</th>  
  5.          <th scope="col">@ViewData["目的港"]</th>  
  6.          <th scope="col">@ViewData["船公司"]</th>  
  7.          <th scope="col">@ViewData["船期"]</th>  
  8.          <th scope="col">@ViewData["航程"]</th>  
  9.          <th scope="col">@ViewData["中转港"]</th>  
  10.          <th scope="col">20GP</th>  
  11.          <th scope="col">40GP</th>  
  12.          <th scope="col">40HQ</th>  
  13.          <th scope="col">@ViewData["附加费"]</th>  
  14.          <th scope="col">@ViewData["有效日期"]</th>  
  15.          <th scope="col">@ViewData["Key_BookOnline"]</th>  
  16.      </tr>  
  17.        
  18.    @if (Model != null && Model.Any())  
  19.    {  
  20.        foreach (var item in Model)  
  21.        {  
  22.            <tr>  
  23.       
  24.                <td>@item.POL_NAME_EN</td>  
  25.                <td>@item.POD_NAME_EN</td>  
  26.                <td>@item.CARR_CODE</td>  
  27.                <td>@item.ETD </td>  
  28.                <td>@item.TRANSIT_TIME</td>  
  29.                <td>@(string.IsNullOrEmpty(item.POT_NAME_EN) ? "直达" : item.POT_NAME_EN)</td>  
  30.                <td> <p class="wz2">@(item.PR_PRICE_20.HasValue?item.PR_PRICE_20.Value.ToString("00"):"")</p></td>  
  31.                <td><p class="wz2">@(item.PR_PRICE_40.HasValue?item.PR_PRICE_40.Value.ToString("00"):"")</p></td>  
  32.                <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加载到需要的地方就可以了

[javascript]  view plain  copy
  1. //拼箱  
  2. var lcl = {  
  3.     //运价查询  
  4.     priceQuery: function (index) {  
  5.         var polName = $("#POL_NAME_EN").combogrid('getValue');  
  6.         var lineName = $("#LineId").combobox('getValue');  
  7.         var podName = $('#POD_NAME_EN').combogrid('getValue');  
  8.         var carrCode = $('#CARR_CODE').combogrid('getValue');  
  9.         $.post('/home/_pxcx', { polName: polName, podName: podName, carrCode: carrCode, lineName: lineName, week: '', boxType: '', page: index }, function (data) {  
  10.             $('#price_box').html(data);  
  11.         });  
  12.     }    
  13. };  
所以用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

PartialViewResult返回的也是一个页面,可以使用@Html.Partial加载这个部分页面,需要多次使用的时候可以用到他

[csharp]  view plain  copy
  1. public PartialViewResult _pxcx(string polName, string podName, string carrCode, string lineName, int page = 1)  
  2.        {  
  3.            int total = 0;  
  4.            var list = _Price_InfoManagement.GetDTO_PRICELCL_List(polName, podName, carrCode, """", lineName, "", page, pageSize, out total);  
  5.            ViewBag.Pager = PagerHelper.CreatePagerByAjax(page, pageSize, total, "lcl.priceQuery"false, lang == "CN");  
  6.            return PartialView(list);//传入集合aps.net会解析好,然后返回一个页面html  
  7.        }  

[html]  view plain  copy
  1. @model List<GTDesk.Domain.MainModule.Entities.DTO.DTO_C_PRICE>    
  2.  <table width="100%" border="0" class="lcl-table tac">  
  3.      <tr id="thead">  
  4.          <th scope="col">@ViewData["起始港"]</th>  
  5.          <th scope="col">@ViewData["目的港"]</th>  
  6.          <th scope="col">@ViewData["船公司"]</th>  
  7.          <th scope="col">@ViewData["船期"]</th>  
  8.          <th scope="col">@ViewData["航程"]</th>  
  9.          <th scope="col">@ViewData["中转港"]</th>  
  10.          <th scope="col">20GP</th>  
  11.          <th scope="col">40GP</th>  
  12.          <th scope="col">40HQ</th>  
  13.          <th scope="col">@ViewData["附加费"]</th>  
  14.          <th scope="col">@ViewData["有效日期"]</th>  
  15.          <th scope="col">@ViewData["Key_BookOnline"]</th>  
  16.      </tr>  
  17.        
  18.    @if (Model != null && Model.Any())  
  19.    {  
  20.        foreach (var item in Model)  
  21.        {  
  22.            <tr>  
  23.       
  24.                <td>@item.POL_NAME_EN</td>  
  25.                <td>@item.POD_NAME_EN</td>  
  26.                <td>@item.CARR_CODE</td>  
  27.                <td>@item.ETD </td>  
  28.                <td>@item.TRANSIT_TIME</td>  
  29.                <td>@(string.IsNullOrEmpty(item.POT_NAME_EN) ? "直达" : item.POT_NAME_EN)</td>  
  30.                <td> <p class="wz2">@(item.PR_PRICE_20.HasValue?item.PR_PRICE_20.Value.ToString("00"):"")</p></td>  
  31.                <td><p class="wz2">@(item.PR_PRICE_40.HasValue?item.PR_PRICE_40.Value.ToString("00"):"")</p></td>  
  32.                <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加载到需要的地方就可以了

[javascript]  view plain  copy
  1. //拼箱  
  2. var lcl = {  
  3.     //运价查询  
  4.     priceQuery: function (index) {  
  5.         var polName = $("#POL_NAME_EN").combogrid('getValue');  
  6.         var lineName = $("#LineId").combobox('getValue');  
  7.         var podName = $('#POD_NAME_EN').combogrid('getValue');  
  8.         var carrCode = $('#CARR_CODE').combogrid('getValue');  
  9.         $.post('/home/_pxcx', { polName: polName, podName: podName, carrCode: carrCode, lineName: lineName, week: '', boxType: '', page: index }, function (data) {  
  10.             $('#price_box').html(data);  
  11.         });  
  12.     }    
  13. };  
所以用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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值