MVC分页控件的使用
1. 引用 using Webdiyer.WebControls.Mvc;
2.
using Webdiyer.WebControls.Mvc; public ActionResult Index(int id=1) { return View(Models.demodata.getlist.OrderByDescending(o=>o.Count()).ToPagedList(id,1)); }
3.数据来源
public class demodata { public static List<string> getlist{ get { List<string> lt = new List<string>(); lt.Add("1"); lt.Add("2"); lt.Add("3"); return lt; } }
4.视图
@using Webdiyer.WebControls.Mvc; @{ ViewBag.Title = "Index"; } @model PagedList<string> <h2>Index</h2> @foreach (var mo in Model) { @mo } @Html.Pager(Model).Options(o => o.SetPageIndexParameterName("id").SetHorizontalAlign("right").SetPagerItemTemplate(" {0}"))
5.访问地址/Home/Index/3