0

I am using asp.net MVC 5 and Was wondering if there were any solutions out there that allowed me to use the PAGEDLIST library that can pass back input variables from the controller ALONG with passing back the .ToPagedList(pagenumber, pagesize) in the return view from the controller.

Here is the code i am working with:

In my Controller:

return View(tags.OrderBy(i => i.entry_no).ToPagedList(page ?? 1, 5));

In my View:

<div class="container-fluid">
    <div class="row">
        <div class="col-xs-4 input-group input-daterange" id="datepicker" style="margin-right: 30px">
            @Html.EditorFor(model => model.startDate, new { @class = "form-control" })
            <div class="input-group-addon">to</div>
            @Html.EditorFor(model => model.endDate, new { @class = "form-control" })
        </div>
        <div class="col-xs-1 input-group">
            <span class="input-group-addon">Desk:</span>
            @Html.DropDownListFor(model => model.SelectedDesk,
         new SelectList(Model.DeskOptions, "Text", "Value", Model.SelectedDesk), new { @class = "selectpicker" })
        </div>
    </div>
</div>

[...]

            Page @(Model.Tag.PageCount < Model.Tag.PageNumber ? 0 : Model.Tag.PageNumber) of @Model.Tag.PageCount

            @Html.PagedListPager(Model.Tag, page => Url.Action("Index", new { page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }))

So what i was hoping for was a way to update those editorfor/displayfor variables above along with passing back a pagedlist for table pagination.

  • Just use a view model containing properties `IPagedList Tags`, `DateTime EndDate`, `int SelectedDesk`, `IEnumerable DeskOptions` etc –  Aug 07 '18 at 22:33
  • And as a side note, using new `SelectList()` in the view to create another identical `IEnumerable` is pointless extra overhead –  Aug 07 '18 at 22:34
  • Thanks Steve, but once the model is updated with the new inputs for example: datetime, selecteddesk, desktoptions, and i return a pagelist of views, will my other inputs be updated back for use as well? i thought return View(tags.OrderBy(i => i.entry_no).ToPagedList(page ?? 1, 5)); only returned a View with a pagedlist and that's all? – user10192547 Aug 08 '18 at 19:40
  • I assume you have misunderstood my comment. Refer [this answer](https://stackoverflow.com/questions/32985561/how-do-i-add-a-model-dropdown-in-a-ipagedlist-model/32986109#32986109) for an example of creating a view model containing an `IPagedList` property –  Aug 08 '18 at 21:55
  • Hi Stephen, wanted to say thanks and looked over some other documentation you helped out on such as [this](https://stackoverflow.com/questions/35540631/paging-on-view-with-mvc-paged-list) But now i'm getting a Keyword, Identifier, string expected when i try to add the two lines of code to display the page and number of pages in my view. I added the two lines of code to the above. – user10192547 Aug 09 '18 at 17:21
  • Also wanted to add that after following that link you posted, the pagination works in limiting the number of entries displayed in my table. But now it just doesn't like it when i try to add the mavigation at the bottom of the table. – user10192547 Aug 09 '18 at 17:28
  • Sorry, but I cannot guess what your code is or what you may be doing incorrectly –  Aug 09 '18 at 22:07
  • thanks Steven, I figured it out based on your input! much appreciated. – user10192547 Aug 10 '18 at 17:03

0 Answers0