如何在 MVC4 排序中发送当前页码?
How to send current page number in MVC4 sorting?
您好,我已经在我的 MVC 应用程序中实现了分页,并且正在实现排序功能。当我点击 header(ActionLink) 我想要排序。这是我的寻呼机代码。
@Html.PagedListPager(Model.logDetails, page => Url.Action("Index",
new { page, currentFilter = ViewBag.CurrentFilter, filterdateTime=ViewBag.filterdateTime, filterdocType= Model.doc_typeid, filteredemployeeID = Model.employeeID, filteredcitizenId = Model.citizenId, sortOrder = ViewBag.currentSort }))
Page @(Model.logDetails.PageCount < Model.logDetails.PageNumber ? 0 : Model.logDetails.PageNumber) of @Model.logDetails.PageCount
这是我要排序的 header。
<th>@Html.ActionLink("Label", "Index", new { sortOrder = ViewBag.LabelSortParm, currentFilter = ViewBag.CurrentFilter, filterdateTime = ViewBag.filterdateTime, filterdocType = Model.doc_typeid, filteredemployeeID = Model.employeeID, filteredcitizenId = Model.citizenId, Page })</th>
我在将当前页码发送回操作方法时遇到问题。除当前页码外,我能够将其发送回操作方法的所有值。谁能告诉我如何在 ActionLink 中获取和发送页码?先感谢您。
在剃须刀视图页面的底部,应该有类似页面导航的内容。在这种情况下,请注意名为 page
的参数。当 UI 发出导航请求时,会将此当前计数传递给 Controller Action 结果方法。
<!--Grid / Page navigations goes here-->
<br />
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("List", new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))
同样的方式,你应该让你的控制器逻辑与此类似。这里还要看一下名为page
的参数。它始终带有当前页码。当我们从 UI 过去时。默认情况下,我将是 0 或 1。
public ViewResult List(string sortOrder, string currentFilter, string searchString, int? page, ManageMessage? message)
{
ViewBag.CurrentSort = sortOrder;
ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "Name_desc" : "";
if (searchString != null) { page = 1; }
else { searchString = currentFilter; }
ViewBag.CurrentFilter = searchString;
var company = getComoanyList();
switch (sortOrder)
{
case "Name_desc":
company = company.OrderByDescending(s => s.Name);
break;
default:
company = company.OrderBy(s => s.Name);
break;
}
int pageSize = 10;
int pageNumber = (page ?? 1);
return View(company.ToPagedList(pageNumber, pageSize));
}
希望对您有所帮助。
您好,我已经在我的 MVC 应用程序中实现了分页,并且正在实现排序功能。当我点击 header(ActionLink) 我想要排序。这是我的寻呼机代码。
@Html.PagedListPager(Model.logDetails, page => Url.Action("Index",
new { page, currentFilter = ViewBag.CurrentFilter, filterdateTime=ViewBag.filterdateTime, filterdocType= Model.doc_typeid, filteredemployeeID = Model.employeeID, filteredcitizenId = Model.citizenId, sortOrder = ViewBag.currentSort }))
Page @(Model.logDetails.PageCount < Model.logDetails.PageNumber ? 0 : Model.logDetails.PageNumber) of @Model.logDetails.PageCount
这是我要排序的 header。
<th>@Html.ActionLink("Label", "Index", new { sortOrder = ViewBag.LabelSortParm, currentFilter = ViewBag.CurrentFilter, filterdateTime = ViewBag.filterdateTime, filterdocType = Model.doc_typeid, filteredemployeeID = Model.employeeID, filteredcitizenId = Model.citizenId, Page })</th>
我在将当前页码发送回操作方法时遇到问题。除当前页码外,我能够将其发送回操作方法的所有值。谁能告诉我如何在 ActionLink 中获取和发送页码?先感谢您。
在剃须刀视图页面的底部,应该有类似页面导航的内容。在这种情况下,请注意名为 page
的参数。当 UI 发出导航请求时,会将此当前计数传递给 Controller Action 结果方法。
<!--Grid / Page navigations goes here-->
<br />
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("List", new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))
同样的方式,你应该让你的控制器逻辑与此类似。这里还要看一下名为page
的参数。它始终带有当前页码。当我们从 UI 过去时。默认情况下,我将是 0 或 1。
public ViewResult List(string sortOrder, string currentFilter, string searchString, int? page, ManageMessage? message)
{
ViewBag.CurrentSort = sortOrder;
ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "Name_desc" : "";
if (searchString != null) { page = 1; }
else { searchString = currentFilter; }
ViewBag.CurrentFilter = searchString;
var company = getComoanyList();
switch (sortOrder)
{
case "Name_desc":
company = company.OrderByDescending(s => s.Name);
break;
default:
company = company.OrderBy(s => s.Name);
break;
}
int pageSize = 10;
int pageNumber = (page ?? 1);
return View(company.ToPagedList(pageNumber, pageSize));
}
希望对您有所帮助。