I’ve got an MVC3 web application that has a general search box and displays items matching the search criteria, with images and description. I would like to allow the user to trim down the result sets by applying filters based upon the data returned using checkboxes. Think Amazon.com, where you may search for Laptop, and on the left side of the page it may show a section ‘Manufacturers’ that displays as checkboxes, a list of all the Manufacturers found (and possibly counts of each one). It may also have a section for Price Range, Processor Size, Memory, etc…
So, if you consider each section as a filter group, the number of groups could be dynamic, but the number of filters per group would definitely be dynamic. I’ve figured out getting the data for these ‘filter groups’, and am not too concerned with gettting them displayed in the view. My question is how do I post back checkbox selections and filter the result set based upon these.
Can I/Should I use AJAX post backs for this? If so, am I calling a Controller Action? What does my Action method return? I’m pretty confused about where to start on this. I have paging, and my filter that’s applied to track and maintain. I’m not sure I’ll be able to get this functionality using MVC without so much work that it won’t be worth it.
yeah I think that using ajax is the best way to go to solve this if you do not want the post pack to happen every time the user selects and decides to filter the results. If you do not want to use ajax you must return an updated view from your HTTP-POST action. here are some examples of how to call action using ajax and passing data to the action.
http://blog.janjonas.net/2011-08-07/asp_net-mvc_3-jquery-ajax-submit-ajax-form-supporting-unobtrusive-client-side-validation-and-server-side-validation
http://www.stefanprodan.eu/2011/04/async-operations-with-jquery-ajax-and-asp-net-mvc/
ASP.NET MVC AJAX with jQuery