PAGEDLIST可以保存当前的URL吗?在ASP.net MVC4中

时间:2014-05-22 05:58:15

标签: asp.net-mvc asp.net-mvc-4 pagedlist

查看

//Some Codes in my VIEW
@foreach (var item in Model._oList)
{
    //Grid table code
}

@Html.PagedListPager((IPagedList)ViewBag.activityList , page => Url.Action("Solution",new { page }),PagedListRenderOptions.OnlyShowFivePagesAtATime)

CONTROLLER

//For my pagination Code
var pageNumber = page ?? 1;
var onePageNumberBugs = _oList.ToPagedList(pageNumber, 5);
ViewBag.activityList = onePageNumberBugs;

首次加载我的页面

(URL:) http://localhost:50969/Home/Solution?value=00003%20

当我从我的页面点击我的分页时,URL将是

(URL:) http://localhost:50969/Home/Solution?page=2

我的问题是,我如何制作这样的网址:

(URL:) http://localhost:50969/Home/Solution?value=00003%20&page=2

(URL:) http://localhost:50969/Home/Solution?page=2&value=00003%20

这样我就可以将我的值用于我的控制器用于其他目的。

4 个答案:

答案 0 :(得分:1)

要保留value,您应该更改您的分页链接,如下所示:

@Html.PagedListPager((IPagedList)ViewBag.activityList , x => Url.Action("Solution",new {value = ViewBag.StoredValue, page = x}),PagedListRenderOptions.OnlyShowFivePagesAtATime)

你的行动将如下:

public ActionResult Solution(string value, int? page)
{
    ViewBag.StoredValue = value;
    //do what you want to do here
}

这里的诀窍是将查询字符串中的value缓存到ViewBag并在您的分页链接中使用它。因此,无论何时转到新页面,您都会将当前value传递给您的操作

答案 1 :(得分:1)

尝试从视图

发送查询字符串中的值
@Html.PagedListPager((IPagedList)ViewBag.activityList , page => Url.Action("Resolution",new { page,value=YOURVALUE }),PagedListRenderOptions.OnlyShowFivePagesAtATime)

答案 2 :(得分:1)

最好将值作为MODEL传递

@Html.PagedListPager((IPagedList)ViewBag.activityList , page => Url.Action("Solution",new { Model.variable_name ,page }),PagedListRenderOptions.OnlyShowFivePagesAtATime)

<强> CONTROLLER

public ActionResult Resolution(int? page, SolutionModel _oSolutionModel)
{ /*Some codes*/ }

答案 3 :(得分:0)

这适合我。

@Html.PagedListPager(Model, p => Url.Action("", "Solution/" , new { p, tanz = Request.Params["value"] }))