.netasp.net-mvcasp.net-mvc-4model-view-controllerpagination

MVC4 - How do I pass IPagedList model to controller


When Paging I am calling an action called RentalSearchResults

as in

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

The model thats passed is blank in the controller

should the action be like this?

public ActionResult RentalSearchResults(IPagedList<Mode> model)
{

}

Solution

  • Actually you're only passing to the controller the page parameter.

    public ActionResult RentalSearchResults(int? page)
    {
    
    }
    

    If you want pass any additional parameter, you should do this:

    @Html.PagedListPager(Model, 
        page => Url.Action("RentalSearchResults", 
        new 
        { 
           page,
           parameter1 = value1,
           parameter2 = value2
        }))
    

    Controller:

    public ActionResult RentalSearchResults(int? page, string parameter1, string parameter2)
    {
    
    }