Asp.net MVC格式后和分页 [英] Asp.net mvc form post and paging
问题描述
我有一个动作方法搜索,当窗体发布被调用。可能有数以千计的搜索resulst基于形式公布值。我想说明逐页搜索查看的页面,但我怎么能知道什么形式值被张贴第一次?这样我可以通过传递页面参数调用搜索查看。
I have an action method Search, which is called when a form is posted. There could be thousands of search resulst based on posted values of form. I want to show Search View page by page, but how can I know what form values was posted first time? so that I can call Search View by passing page parameters.
推荐答案
在我的应用程序,为电网提供数据的所有操作方法都作为参数,这个类的一个实例:
In my app all the action methods that provide data to grids take as a parameter an instance of this class:
public class QuerySettings
{
private int page;
public QuerySettings()
: this(true)
{
}
public QuerySettings(bool pagingEnabled)
{
this.Page = 1;
this.Rows = 10;
this.PagingEnabled = pagingEnabled;
}
public int Rows { get; set; }
public string SortColumn { get; set; }
public string SortOrder { get; set; }
public string Search { get; set; }
public bool PagingEnabled { get; set; }
public int Page
{
get { return page; }
set { page = Math.Max(1, value); }
}
}
此目的是通过它可以使用通过采取适当的排序/过滤信息业务层传递给服务方法英寸然后,他们返回包裹在数据:
This object is passed to service methods in by Business Layer which can use the information passed to apply appropriate sorting / filtering. They then return the data wrapped in:
public class QueryResult<T>
{
public QueryResult()
{
}
public QueryResult(QuerySettings settings, IList<T> items, int currentPage, int totalPages, int totalItems)
{
Settings = settings;
Items = items;
CurrentPage = currentPage;
TotalPages = totalPages;
TotalItems = totalItems;
}
public QuerySettings Settings { get; private set; }
public int CurrentPage { get; private set; }
public int TotalPages { get; private set; }
public int TotalItems { get; private set; }
public IList<T> Items { get; private set; }
public IEnumerable<T> AsEnumerable()
{
return this.Items;
}
}
这篇关于Asp.net MVC格式后和分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!