2017-04-04 74 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)