簡體   English   中英

ASP.NET MVC。 PagedList通過多個參數過濾

[英]ASP.NET MVC. PagedList filtering by multiple params

我有一個帶有過濾器參數的網頁,並創建了一個簡單的類,以使用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 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();
    }

過濾效果很好,但是如果使用分頁控制,參數將丟失。

分頁助手:

@Html.PagedListPager((IPagedList)ViewBag.Documents, 
page => Url.Action("Index", new { page , filter = (Document)ViewBag.filter}))
//Also tried Model instead of ViewBag.filter

我無法將參數傳遞給動作控制。

有什么辦法嗎?

您需要使用ajax調用而不是助手。 編寫ajax調用並將參數作為post方法傳遞。

好像從未設置過ViewBag.filter,因此無法進行分頁。

這是一個很好的教程,可以詳細回答您的問題: http : //www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/sorting-filtering-and-paging-在一個ASP.NET MVC應用程序中使用實體框架

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM