I need to be able to provide a page for the end user where thay can search in the following :
- Search work
- Category
- Price
- AdType
- Location
and so on.
Its important that the user can copy the url and then use it later(and get the same settings). Its also important to be able to save these settings on the user in the database.
So far I have created a ModelView class that contains the parameters but I am not sure that this is the right way to go? Maby I should pass all inte the URL.
If so, how do I accomplish this? Is there any samples I could look at?
BestRegards
The least problematic way is to pass the parameters in the queryString.
There’s nothing non-MVC about this approach. In fact, you may see ActionLinks generated using QueryString parameters when passing parameters that don’t correspond to model fields.
You could create a route like
but, in my opinion that’s the wrong way to go. I assume, possibly incorrectly, that using a route would make the URL more search engine-friendly, but that’s only an issue if you want different combinations of search urls to be discoverable by an external search engine, which really doesn’t make as much sense as a sitemap.
Update:
If you declare your action like so:
Then your queryString parameters will be mapped to the action method parameters.
All you’ll need to do is set your form “method” to GET,
to get your fields passed as query string parameters instead of form POST data.