0

Hi, this is my Controller Code:

public ActionResult Create()
{
      makelist = new SelectList(db.CountryMasters.ToList(), "CountryID", "CountryName",1);
        ViewData["CounrtyMaster"] = makelist;

        var modelList = new CascadingSelectList(clientMasterManagement.GetState(makelist.SelectedValue.ToString()), "StateID", "StateName");
        ViewData["StateMaster"] = modelList;

        return View("Create");
} 

and this is my View Code:

<div class="editor-field">
    <%= Html.DropDownList("CountryID", ViewData["CounrtyMaster"] as SelectList)%>
    <%= Html.ValidationMessageFor(model => model.CountryID) %>
</div>

<%= Html.CascadingDropDownList("StateMaster","CountryMaster")%>

when I select upper list it's not affecting the second one, can anyone help me here???

Rui Jarimba
  • 11,166
  • 11
  • 56
  • 86
Niket
  • 11
  • 3

2 Answers2

0

User CascadingSelectList function instead of SelectList in your controller action

var makelist = new SelectList(db.CountryMasters.ToList(), "CountryID", "CountryName",1); ViewData["CounrtyMaster"] = makelist;
var modelList = new CascadingSelectList(clientMasterManagement.GetState(makelist.SelectedValue.ToString()), "StateID", "StateName");
ViewData["StateMaster"] = modelList;
Adeel
  • 19,075
  • 4
  • 46
  • 60
0

Html.CascadingDropDownList is not a standard MVC helper. I take it that you are using Stephen Walther's helper. If so this question will help you out:

ASP.NET MVC - Cascading Drop Down

Community
  • 1
  • 1
Paul Hiles
  • 9,558
  • 7
  • 51
  • 76
  • I've use the same code given in Stephen Walther's helper but when I select an item from first listbox it doesn't affect another – Niket Jan 27 '11 at 12:07