我有一个搜索控制器,它有大量参数(搜索条件)。我想使用MVCContrib - IPagination翻阅结果。这一切都很好,问题是如何在Html.Pager上生成链接。我在视图中试过这个
@ Html.Pager(Model.Results).Link(p => Url.Action(“搜索”,新{ Model.Criteria}))
但是不起作用。我是否需要注册路线以便Url.Action了解如何形成链接?
以下控制器代码......
public ViewResult Search(JobSearch search, int? page, IAuthenticatedUser authenticatedUser)
{
// perform search
var query = _jobRepository.CreateQuery<IPagedJobSearch>();
query.SiteId = authenticatedUser.SiteId;
query.JobId = search.Criteria.JobId;
query.Lot = search.Criteria.LotNumber;
query.Street = search.Criteria.StreetInfo.Name;
query.StreetNumber = search.Criteria.StreetInfo.Number;
query.Suburb = search.Criteria.Suburb;
query.Council = search.Criteria.Council;
query.ClientRef = search.Criteria.ClientOrderNumber;
query.ItemsPerPage = 15;
query.PageNumber = page ?? 1;
var pagedResult = query.Execute(); ......
答案 0 :(得分:1)
您没有显示所有标记,但您需要指定每个参数,如下所示:
<%= Html.Pager(Model.AssetsPagedList)
.First("First")
.Last("Last")
.Next("Next")
.Previous("Previous")
.Link(currentPage => Url.Action("Browse", new {
page = currentPage,
searchTerm = Model.SearchModel.SearchTerm,
excludedWords = Model.SearchModel.ExcludedWords,
minPrice = Model.SearchModel.MinPrice,
maxPrice = Model.SearchModel.MaxPrice,
locationId = Model.SearchModel.LocationId,
catalogId = Model.SearchModel.CatalogId
}))
%>
获得正确的参数后,您需要创建一个接受每个参数的控制器:
public ActionResult Browse(int? id, string searchTerm, int? locationId,
GridSortOptions gridSortOptions, int? page, string excludedWords,
decimal? minPrice, decimal? maxPrice, int? catalogId)
{
}