【问题标题】:ASP.NET MVC Html.PagedListPager Not WorkingASP.NET MVC Html.PagedListPager 不工作
【发布时间】:2016-01-28 14:40:05
【问题描述】:

我的控制器:

    public ActionResult Index(String SearchString, int? page)
    {
        var query = from _mytable in _MyDataContext.MyTables select _mytable;

        int pageSize = 10;              // will only contain 10 products max because of the pageSize
        int pageNumber = (page ?? 1);   // if no page was specified in the querystring, default to the first page (1)

        PagedList.PagedList<MyTables> models = new PagedList.PagedList<Anlagen>(query, pageNumber, pageSize);

        return View(models);
    }

MyView,最后一行:

@Html.PagedListPager(Model, page => Url.Action("Index", new { ViewBag.SearchString, page}))

我不知道为什么,但唯一的分页是: «|‹|1|›|»

使用“?SearchString=hello&page=2”调用页面效果很好,但分页相同: «|‹|1|›|»

这是我的搜索表单:

<form action="@Url.Action("Index", "Anlagen")" method="get" role="search" class="navbar-form-custom">
    <div class="form-group input-group">
        <input type="text" class="form-control" placeholder="suchen..." id="SearchString" name="SearchString" value="@ViewBag.SearchString" />
    </div>
</form>

只是一个工作项目的副本,但在一个新项目中它不起作用:(

【问题讨论】:

    标签: asp.net-mvc pagedlist


    【解决方案1】:

    我相信您必须订购您的元素,PagedList 才能正常工作。调整您的 LINQ 以按某个值排序您的集合,例如 Name(如果存在):

    var query = from _mytable in _MyDataContext.MyTables orderby _mytable.Name select _mytable;
    

    【讨论】:

    • 抱歉,不,结果相同:«|‹|1|›|»
    • 您能显示为寻呼机生成的 HTML 吗?另外,您是否使用了任何可能无意中导致某些问题的样式/库?
    • 亲爱的 Chase,很抱歉我的延误 - 几个月后,这是分页器生成的 HTML:`
      `
    【解决方案2】:
        This is  best Solution for PAGEDLISTPAGER in mvc5 :
    
        @Html.PagedListPager(Model,Page => Url.Action("Index",new { Page,    SearchBy=Request.QueryString["SearchBy"],
        Search = Request.QueryString["Search"] }), new PagedListRenderOptions() {Display=PagedListDisplayMode.IfNeeded
        ,DisplayPageCountAndCurrentLocation=true,DisplayItemSliceAndTotal=true
         } )
    
    
    //////////////////////////////////////////////////////////////////////////////
        ///////////Solution////////browser back button give problem in MVC when logout////////////////////////////////////////////////////////////
    
        I had this problem a while ago, disabling the cache for the entire application solved my problem, just add these line to the Global.asax.cs file
    
                protected void Application_BeginRequest()
                {
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
                    Response.Cache.SetNoStore();
                }
    

    【讨论】:

      猜你喜欢
      • 2011-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多