0

I am working on a model criteria builder. I have a dropdown list with all of the model properties, a dropdown list with static operators (less than, equals, like, etc) and a user input form element for the value. The issue is that the form element type (dropdown, date, text box, etc) for the user input value needs to be based on the data type of the model property chosen in the first dropdown list. What is the best way to achieve this using MVC 2? Ideally I would like to just create an Html extension method and use it like Html.CriteriaFilterFor(model => model) and be able to customize the display using model attributes and metadata.

tereško
  • 58,060
  • 25
  • 98
  • 150
robbymurphy
  • 741
  • 2
  • 5
  • 16

1 Answers1

0

You should use JQuery to populate the other one. An AJAX call would allow you to pull the second drop down's list. Populating Dropdownlist Using MVC2 Based On Another Dropdownlist (Cascading DropDownList)

Community
  • 1
  • 1
Ryand.Johnson
  • 1,906
  • 2
  • 16
  • 22
  • This is what I'm doing in my current implementation. The problem is that I don't know how to make it scale. The input will not always be a dropdown list. It would ideally be driven by model metadata. How can I incorporate the metadata into the method that is called on the server side? – robbymurphy Nov 08 '11 at 10:35
  • I see two options off the top of my head. First, create hidden div's with all the correct fields (drop downs, textboxes, etc) already in it and display/hide each div as they change the main drop drown. You could use jquery show and hide to accomplish it. Here is a link http://api.jquery.com/show/. Second, you could have a container div and set the html $("#contentDiv).html(). You would build all the html dynamically depending on the metadata. You put the html in a variable and then add it to the div via the .html() method. – Ryand.Johnson Nov 08 '11 at 16:52