csharp 排序,分页,过滤Paging.mvc

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 排序,分页,过滤Paging.mvc相关的知识,希望对你有一定的参考价值。


		 * Paging, filtering and sorting with Paglist.mvc
		public ActionResult Index(int? page, string currentFilter, string sortOreder)
		{   
			// Action Resault filtering, Paging, Sorting
			
			ViewBag.CurrentSort = sortOreder;
			user Us = (user)Session["LoginUser"];
			if (Us == null)
			{	
				return RedirectToAction("Login", "Home");
			}
			OurdbDataContext db = new OurdbDataContext();
			var Students = db.test_sells.AsQueryable();
			// Sortin page
			ViewBag.NameSortParm = String.IsNullOrEmpty(sortOreder) ? "name_desc" : "";
			ViewBag.DateSortParm = sortOreder == "Date" ? "date_desc" : "Date";
			switch (sortOreder)
			{
				case "name_asc":
					Students = Students.OrderBy(x => x.Name);
					break;
				case "name_desc":
					Students = Students.OrderByDescending(x => x.Name);
					break;
			}
			//Sort end
			// Paging with Pagelist.mvc
			int pageSize = 10;
			int pageNumber = (page ?? 1);
			return View(Students.ToPagedList(pageNumber, pageSize));
			// paging end
			
		}.
		
		
		
// in View
//Model to use
@using PagedList.Mvc
@model PagedList.IPagedList<welcome_party.Models.test_sell>
//html helpers
<!--Page (Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of Model.PageCount-->
<!--Html.PagedListPager(Model, page => Url.Action("Index", new { page, sortOreder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))-->
@Html.ActionLink("სახელი", "Index", new {/*filter with mvc*/ sortOreder = ViewBag.NameSortParm }) 

以上是关于csharp 排序,分页,过滤Paging.mvc的主要内容,如果未能解决你的问题,请参考以下文章

用于排序、分页和过滤的 CodeIgniter 优雅库 [关闭]

带有分页、排序和过滤的 WebAPI Get 方法

Laravel(三)分页排序和过滤

您如何处理排序、分页和过滤的参数?

自己的 CollectionView 用于分页、排序和过滤

表格的排序过滤与分页