【问题标题】:Can a PAGEDLIST save the current URL? in ASP.net MVC4PAGEDLIST 可以保存当前 URL 吗?在 ASP.net MVC4 中
【发布时间】:2014-05-22 05:58:14
【问题描述】:

查看

//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)

控制器

//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

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

【问题讨论】:

  • 我的分页操作??在我的控制器中

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


【解决方案1】:

尝试从视图中发送查询字符串中的值

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

【讨论】:

    【解决方案2】:

    最好将值作为模型传递

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

    控制器

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

    【讨论】:

      【解决方案3】:

      要保留你的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 传递给您的操作

      【讨论】:

      • 我已关注并复制了您的代码,但 Value = null
      • 答案已更新,更改Url.Action 部分。请告诉我它是否适合你
      • 值仍然是null
      • 在点击分页链接之前,您是否导航到此localhost:50969/Home/Solution?value=00003%20 URL?
      【解决方案4】:

      这对我有用。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-15
        • 1970-01-01
        • 1970-01-01
        • 2013-10-09
        • 2013-12-26
        • 2014-06-28
        • 2015-03-07
        • 1970-01-01
        相关资源
        最近更新 更多