C# NETMVC。按多个参数筛选页面列表
我有一个带有过滤器参数的网页,并创建了一个简单的类,通过Where()方法来处理这些参数 但是通过Html.Action传递参数有一个问题 搜索选项:C# NETMVC。按多个参数筛选页面列表,c#,asp.net,entity-framework,filtering,paging,C#,Asp.net,Entity Framework,Filtering,Paging,我有一个带有过滤器参数的网页,并创建了一个简单的类,通过Where()方法来处理这些参数 但是通过Html.Action传递参数有一个问题 搜索选项: public class Document { public string Name { get; set; } public string Title { get; set; } public string Param1{ get; set; } public string Param2{ get; set; }
public class Document
{
public string Name { get; set; }
public string Title { get; set; }
public string Param1{ get; set; }
public string Param2{ get; set; }
}
控制器动作
public ActionResult Index(int? page, Document filter)
{
ViewBag.Params= documentFilter;
IEnumerable<Document> DocumentList = dbContext.Documents.ToList();
DocumentList = DocumentList.CustomFilter(documentFilter);
var pageNumber = page ?? 1;
var onePageOfProducts = DocumentList.ToPagedList(pageNumber, 50);
ViewBag.Documents = onePageOfProducts;
return View();
}
我无法将参数传递给动作控制
有没有办法做到这一点 您需要使用ajax调用而不是helper。编写ajax调用并将参数作为post方法传递 看起来ViewBag.filter从未设置,因此您的分页将无法工作 下面是一个很好的教程,可以详细回答您的问题:
Model
不起作用,因为您没有将模型传递给视图,只是使用了ViewBag
。老实说,为了学习的目的,你可以假装ViewBag
根本不存在。你使用它的方式会起作用,但它太草率了。
@Html.PagedListPager((IPagedList)ViewBag.Documents,
page => Url.Action("Index", new { page , filter = (Document)ViewBag.filter}))
//Also tried Model instead of ViewBag.filter