2017-04-04 73 views
0

眼下,在視圖文件我的網頁鏈接,我有:添加PARAMS到頁面鏈接(.NET MVC)

Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount 
@Html.PagedListPager(Model, page => Url.Action("Index", 
    new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter, numberPerPage = ViewBag.numberPerPage, submit = ViewBag.submit })) 

然而,由於過濾器,當一個人搜索數據時,可以PARAMS更改,使網址如下所示:

http://localhost:000/Search?Category=Cats&Category=Dogs&SearchString=brown&numberPerPage=10&submit=adoptable 

如何將這些添加到視圖頁?用戶可能不使用過濾器。我通過ViewBag抓取他們,所以他們在那裏的HTML像:

cats,dogs 

謝謝。

+1

能告訴你的操作方法和查看? – Win

+0

我想通了。我會在下面添加答案。 – yondaimehokage

回答

0

我想出瞭如何去做我需要的。讀起來,特殊的URL只能作爲字符串附加到Url.Action。所以我所做的就是:

public ActionResult Index(string SearchString, string sortOrder, string currentFilter, string numberPerPage, int? page, string[] Category) 
{ 

    .......... 

    ViewBag.CategoryPager = ""; 
    foreach (var singleCategory in Category) 
    { 
     ViewBag.CategoryPager += "&Category=" + Category.Replace(" ", "%20"); 
    } 

    ......... 

    return View(searchResults.ToPagedList(pageNumber, pageSize)); 
} 

並在視圖:

Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount 
@Html.PagedListPager(Model, page => Url.Action("Index", new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter, numberPerPage = ViewBag.numberPerPage }) + ViewBag.CategoryPager)