PagerHelper for ASP.NET MVC3
来源:互联网 发布:qq空间网络音乐 编辑:程序博客网 时间:2024/05/01 01:59
PagerHelper for ASP.NET MVC3 makes it easier for add pagination to your website.
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; } }}
Then use the @Html.Pager helper method in the view and pass to it an instance ofPagerViewModel 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)
Also you can use the Skip and Take properties fromPagerViewModel to help you in your controller. The only important thing that we have to do previous usingSkip andTake is to set TotalItems property.
public ActionResult Index(SearchProducViewModel searchProducViewModel){ ViewBag.EnhancePage = true; ViewBag.Action = "Index"; DoIndex(searchProducViewModel); if (Request.IsAjaxRequest()) { return PartialView("ProductsGrid", searchProducViewModel); } else { return View("Index",searchProducViewModel); }}
private void DoIndex(SearchProducViewModel searchProducViewModel){ if (searchProducViewModel.Delete > 0) { Product product = products.Where(x => x.Id == searchProducViewModel.Delete).Single(); products.Remove(product); } var filteredProducts = from p in products where p.Active == searchProducViewModel.Active && (searchProducViewModel.Name == null || p.Name.Contains(searchProducViewModel.Name)) select p; searchProducViewModel.PagerViewModel.TotalItems = filteredProducts.Count(); searchProducViewModel.ListOfProducts = filteredProducts .Skip(searchProducViewModel.PagerViewModel.Skip) .Take(searchProducViewModel.PagerViewModel.Take);}
Demo http://pagerhelper.apphb.com/
http://pagerhelper.codeplex.com/
- PagerHelper for ASP.NET MVC3
- 初探 Asp.net MVC3
- Asp.net MVC3基础
- asp net mvc3 ViewBag
- Asp.net MVC3基础
- ASP.NET MVC3实践
- asp.net mvc3总结
- Asp.Net MVC3+ExtJS4
- ASP.NET MVC3 概要
- ASP.NET MVC3--视图
- ASP.NET MVC3
- ASP.NET MVC3 技术(七) ASP.NET MVC3 项目部署
- ASP.NET MVC3 技术(七) ASP.NET MVC3 项目部署
- ASP.NET MVC3 技术(七) ASP.NET MVC3 项目部署
- Asp.net mvc3 不支持vs2008
- ASP.NET MVC3 概览 一
- ASP.NET MVC3 Razor 语法
- asp.net MVC3 Get Json
- 算法:将table标识的树形结构文本数据快速导入Mysql邻接表
- 表单提交数据请求 get和post的 区别
- 个人网站如何在互联网时代下求生存
- WPF TreeView HierarchicalDataTemplate
- 提高你的Java代码质量吧:在switch的default代码块中增加AssertionError错误
- PagerHelper for ASP.NET MVC3
- CoreAudio实现录音播音和扬声器听筒模式的切换
- Redis配置文件详解
- think in java interview-高级开发人员面试宝典(一)
- 一个尘封的收购故事
- 中国的大学里垮掉的一代---武大校长的一封信
- 阻塞模式下的send、recv、close总结
- Delphi for iOS开发指南(8):在iOS应用程序中使用Tab组件来显示分页
- TTL电平,CMOS电平,OC门,OD门基础知识