0

hi i have two dropdowns.

  1. MasterModule(country)
  2. Submodule(state)

My expectation is to First select Master category(country) than select(state)..

Currently it is showing all states when i selec any of country.

I have following razor code

<div class="editor-label">
                @Html.LabelFor(model => model.MasterID, "Department")
            </div>
            <div class="editor-field">
                @Html.DropDownList("MasterID", String.Empty)
                @Html.ValidationMessageFor(model => model.MasterID)
            </div>

            <div class="editor-label">
                @Html.LabelFor(model => model.SubId, "Employee")
            </div>
            <div class="editor-field">
                @Html.DropDownList("SubId", String.Empty)
                @Html.ValidationMessageFor(model => model.SubId)
            </div>

any help how to acheive this?

Above code is simply binding the dropdown values to both , i want submodules dropdown shows only states of selected country. and always shows values only when i select the country

Jot Dhaliwal
  • 1,470
  • 4
  • 26
  • 47
  • 3
    You need to use javascript/jquery to achieve this - typically by handling the change event of the first dropdown, and calling an action method to return the states based on the selected country, then updating the html of the states dropdown –  Aug 28 '14 at 11:44
  • Yes , can i bind onchange() method to my above dropdown – Jot Dhaliwal Aug 28 '14 at 18:23

1 Answers1

1

This question describe the same situation that you would like to have, see the accepted solution: Fill drop down list on selection of another drop down list

Solution found by Jot: http://articlemirror.blogspot.in/2014/01/populate-cascading-dropdown-list-in.html

Community
  • 1
  • 1
adelb
  • 791
  • 7
  • 26