Jeyhun Rahimov
Jeyhun Rahimov

Reputation: 3787

How to create 2 related dropdownlists

I have mvc3 (with C#) application about phone accessories. There is Accessory model that it has Tag property. When I create new Accessory object, I give some values to its Tag property as Nokia, Samsung, E55, C15, Blackberry etc. I will use Tag property in accessories searching. In search time, I want user select phone name from dropdownlist, then in other dropdownlist that phones models dynamically are loading. For examlpe, when I select Nokia, in bottom dropdownlist Nokia's models are loading as N8, E51, E55, etc..

How can I determine Phone name and its models lists and bind those dynamically?

Upvotes: 1

Views: 157

Answers (2)

Chris Snowden
Chris Snowden

Reputation: 5002

Use Ajax.BeginForm with a Partial View to replace the contents of the 2nd drop down. You can use Javascript to use the 1st drop down list's onchange event to post back the Ajax form.

Make sure you also include:

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

for Ajax to work with MVC3 asuming you're using unobtrusive javascript default config settings.

Upvotes: 1

Related Questions