I am developing an online store using asp mvc 3 and I am using Razor views. I am new to MVC and I have an issue about filtering products.
My approach was:
- define public PartialViewResult Filter() and include it in the _Layout.cshtml to be rendered on all pages
- when user submit the filter form show him the products that match the rules. For this I ahve another action public ActionResult FilterResult(FilterModel model)
Questions:
-
The problem with this approach is that the form do a post and user cannot copy the filter url to send by email. I would like to have the parameters in the url. Is this possible using mvc 3? Or should I use javascript to do the filter redirection?
-
Do you know a better and more elegant approach of the filtering products problem?
Just use GET method for your form, and you will have filter parameters in URL.
Example:
It is possible with BeginForm helper : FormExtensions.BeginForm Method (HtmlHelper, String, String, FormMethod), for submit to same page, it is :