The Model of SearchResults.aspx
is an instance of PersonSearch
; when the request for a new page arrive (a GET request), the action method should take it and compute the new results.
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult SearchResults(PersonSearch search, int? page)
{
ViewData["Results"] = new PaginatedList<Person>(_searchService.FindPersons(search), page ?? 0, 1);
return View("SearchResults", search);
}
Then I have to generate the previous/next links:
<%= Html.ActionLink("Next Page >", "SearchResults", routeValues) %>
If I use routeValues = ViewData.Model
I can see the object properties passed the address, but I can't add the "page" parameter.
Route values are the values extracted from a URL based on a given route template. Each route parameter in a template will have an associated route value and is stored as a string pair in a dictionary.
Where RegLookup is a get ActionResult method in the vehicle controller which goes away and finds the model/make/colour information based on the registration field passed through to it. The Make/Model/Colour information is retrieved from a separate database.
The value will only be added as query string values if its FormMethod. Get (and you can remove the route values from the BeginForm() method). But what is the point of this - they are hidden inputs, not editable values.
RouteData is a property of the base Controller class, so RouteData can be accessed in any controller. RouteData contains route information of a current request. You can get the controller, action or parameter information using RouteData as shown below.
It think it would be better to create another object with the correct values, instead of using (and potentially altering the current routevalues):
<%=Html.ActionLink("Next Page >", "SearchResults", new {
search = this.Model,
page = 1 //or whatever
}) %>
This blog post by Scott Guthrie helped me wrap my head around URL Routing: ASP.NET MVC Framework (Part 2): URL Routing
I love that he included test cases!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With