简体   繁体   中英

Passing PaginatedList to ActionResult MVC C#

I wanted to create a simple paginated search for my project. I'm having trouble with my 'advanced search' page, where I have several textbox inputs that the user would fill with the appropriate data (basically just several filters).

My view is strongly-typed with the paginatedList class similar to the NerdDinner tutorial.

In my controller, I wanted to pass the PaginatedList as a parameter since my view contains several bits of info from the PaginatedList model. The PaginatedList was null (as parameter), then I changed added the route; the object itself is not null anymore, but the values are.

View:

<%= Html.TextBox("Manufacturers", Model.Manufacturers) %>
<%= Html.TextBox("OtherFilters", Model.FilterX) %>
//...etc etc

Controller:

public ActionResult AdvancedSearchResults(PaginatedList<MyModel> paginatedList) {
//...
}

Any ideas? Am I even going about this correctly? Should I create a ViewModel that encapsulates the paginatedList info as well as the additional info I need instead?

You may want to create SearchCriteria class which contains user's input data for filtering.

Controller will have the Action as below:

public ActionResult AdvancedSearchResults(SearchCriteria criteria)
{
    PaginatedList<MyModel> result = SearchService.Search(criteria);
    return View(result);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM