如何在我的视图页面上设置分页? [英] How will I set pagination on my View Page?
本文介绍了如何在我的视图页面上设置分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public static List<crbt_promotion> getplinks()
{
List<crbt_promotion> plinks = new List<crbt_promotion>();
using (crbt_onwebEntities dbContext = new crbt_onwebEntities())
{
plinks = (from z in dbContext.CRBT_Promotion select z).OrderByDescending(x=>x.id).ToList();
}
return plinks;
}
以上是我在类文件中编写的方法而不是在控制器中,下面是我的查看页面: -
Above is my method written in class file not in controller and below is my View Page :-
@{
List<mvclogin.models.crbt_promotion> listCRBT_pro = mvclogin.service.implement.getplinks();
ViewBag.Title = "CRBT Promotional Portal";
}
<div>
<table>
<tr style="background:#f4f4f4; height:20px; width:100%">
<th align="center">ID</th>
<th align="center">Album Name</th>
<th align="center">Song Name</th>
<th align="center">Link</th>
<th align="center">Creation Date</th>
</tr>
@{
if(listCRBT_pro.Count>0)
{
foreach(mvclogin.Models.CRBT_Promotion promotionlist in listCRBT_pro)
{
<tr class="divmis">
<td>@promotionlist.id</td>
<td>@promotionlist.AlbumName</td>
<td>@promotionlist.SongName</td>
<td>@promotionlist.Link</td>
<td>@promotionlist.CreationDate</td>
</tr>
}
}
}
</table>
</div></mvclogin.models.crbt_promotion></crbt_promotion></crbt_promotion></crbt_promotion>
推荐答案
首先,在您希望通过分页功能增强的项目中的任何视图模型中实现IPagable。
First, implement IPagable in any viewmodel that you have in your project that you want to enhance with Pagination functionality.
namespace ar.com.juanpabloibanez.Samples.ViewModels
{
public class SearchProducViewModel : IPageble
{
public SearchProducViewModel()
{
PagerViewModel = new PagerViewModel();
}
public PagerViewModel PagerViewModel { get; set; }
public IEnumerable<Product> ListOfProducts { get; set; }
public bool Active { get; set; }
public string Name { get; set; }
public int Delete { get; set; }
}
}
然后使用 @ Html.Pager辅助方法在视图中并传递一个PagerViewModel类的实例,您可以从模型中获取该实例。
Then use the @Html.Pager helper method in the view and pass to it an instance of PagerViewModel class that you can obtain from your model.
@using ar.com.juanpabloibanez.MVC.PagerHelper.Helpers
@using ar.com.juanpabloibanez.Samples.ViewModels
@model SearchProducViewModel
<table>
<thead>
<tr>
<th>Name</th>
<th>Price</th>
<th>Active</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach (var product in Model.ListOfProducts)
{
<tr>
<td>@product.Name</td>
<td>@product.Price</td>
<td>@product.Active</td>
<td><button name="Delete" value="@product.Id" type="submit" class="deleteButton">Delete</button></td>
</tr>
}
</tbody>
</table>
@Html.Pager(Model.PagerViewModel)
请查看此链接了解更多信息: PagerHelper for ASP.NET MVC3
这篇关于如何在我的视图页面上设置分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文