views:

377

answers:

1

I have a page with several drop down lists that all have the same contents. The page starts out with only three ddls, but more need to be added based on user input. There is also other information associated with the drop down lists that is all in a table. So, when the user clicks a link I add a new row of textboxes and drop down lists to a table.

When I add a row to my table, the new drop down lists are empty because there is no view data associated with them. How can I use ajax or jquery to pull the viewdata that I need to populate new drop down lists?

A: 

If I understand you correctly, you don't really need to make an AJAX call to get at the viewdata needed for the new ddls. You already have the information, so it is just a matter of organizing it.

  1. You could perhaps just make a copy of one of the existing ddls (cf. jQuery's clone() method)
  2. You could create a hidden ddl that you use as a template and use jQuery's clone() method.
  3. You could store the required information in some other way - you will have to evaluate what will be appropriate yourself, or check back here with more info
  4. You could fetch the required data using an AJAX request. In that case you probably want to create an action returning a JsonResult containing the required data. If you choose this approach, beware of this subtle JSON security issue.
Rune