Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using a default (generated) List view, and would like to add filtering to it with DropDown values. I would prefer to do so without resorting to jQuery or JavaScript, and instead use plain vanilla controller actions to do this.

I have several components to this question:
1. Do I need to add a new route for the Index action to add parameters?
2. How do I cause a button to call that new parameterised controller action?
3. If I wanted to use a little script to call that action when dropdown values change, what should I do?

I am using a custom viewdata object, which contains my main model data as well as lists required for the dropdowns.
Posted
Updated 2-Aug-10 9:25am
v2

1 solution

I really don't know how your page is built but I would recomend the following:
Put the DropDowns that you use to set the filter in a Ajax.Form and set the form to update the panel (div) where the result data should be. That can even contain the form it self.
set the onChange event of the drop downs to submit the form.
That will make the page to post a request to the server with the drop downs values where you can update the result panel without refreshing the whole page.
You will not need a new route just an action in the existing controller to handle the filter posts.
If you want to apply the filter only when a button is pressed instead of using the onChange event of the DropDown submit the form in the onClick event of the button.
You don't need new parameters the seected values of the DropDowns will be submited as form data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900