views:

62

answers:

1

I am trying to add some filter logic to a document database. The list of select lists varies by which product and category a user has selected.

/productx/marketing would have selectlista, selectlistb, and selectlistc

while

producty/marketing would have selectlista, selectlistd, and selectliste

I am struggling to visualize how i can accomplish this. My 1st thought was a single view that iterates over a "list of selectlists and renders a html.dropdown for each element. But i am unsure how to create this list of selectlists for the view to iterate. Has anyone else addressed a similar problem? If so what approach did you end up using to solve it?

A: 

The way that I have typically bound select lists to drop down lists is via the viewData dictionary. You create a select list then populate ViewData:

ViewData["DropDownListName"] = yourSelectList;

So I don't think I would use a list of SelectLists all though you could if you use option 1 below but the framework can handle the binding for you. I think you do though have a couple of options.

1. Create all of your drop down lists in the view and pass all the select lists through the view data and then hide or show them based on your selected product. Either by using asp.net if statements in the view or javascript if the product is selected at the top of the page and thus isn't known when the page is initially created.

2. If your product is selected at the top of the page before the select lists you could use an AJAX call to a action method that returns a JsonResult conatining your drop down list items and use JQuery to populate your drop down lists that way.

Dean Johnston