我喜歡傳遞一個對象作爲參數來搜索動作,然後將參數對象傳遞給視圖。因此,在您的控制器像這樣的代碼(注意:我使用的是Rob Conery's PagedList class):
public class SearchParameters {
public string School { get; set; }
public int? StateID { get; set; }
public int? Page { get; set; }
public SearchParameters GetPage(int page) {
return new SearchParameters {
School = School,
StateID = StateID,
Page = page
};
}
}
public class SearchViewModel {
public PagedList<[YourResultType]> Results { get; set; }
public SearchParameters Parameters { get; set; }
}
// ...
public ActionResult Search(SearchParameters parameters) {
IQueryable<[YourResultType]> query;
// ... do some stuff to get your search results
return View("Search", new SearchViewModel {
Results = query.ToPagedList(parameters.Page - 1), 15),
Parameters = parameters
});
}
所以,你的搜索查看從一般的ViewPage <牛逼>繼承與頁面的聲明是這樣的:
<%@ Page ... Inherits="ViewPage<SearchViewModel>" %>
然後在你的搜索視圖中,你可以做這樣的事情...
<% for(int i = 0; i < Model.Results.TotalPages; i++) { %>
<%= Html.ActionLink(i + 1).ToString(), "Search",
Model.Parameters.GetPage(i + 1)) %>
<% } %>
它沒有拿起額外的參數。我的鏈接以/ Program/List?page = 2而不是/ Program/List?categoryIDs = 2&categoryIDs = 3&categoryIDs = 4&categoryIDs = 5&school =&stateID =&page = 2 – Jonathan 2009-02-05 05:02:56
@Haacked,你知道他們正在重新制作電影頭像?塞繆爾·傑克遜將扮演那個傢伙。 – mmcdole 2009-02-05 08:46:21