Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on MVC, I want to bind cascading dropdownlist, such like "country" and "state", since i have cascading dropdownlist i binds my first dropdownlist for "country" in my Index action and then on selection of "country" in first dropdownlist i want to bind my second dropdownlist for "state", but on action method "country" dropdown will be bid successfully but for state dropdownlist i does not specify any viewbag or viewdata, i have got an error "there is no viewdata for selectlistitem with state key",

so it is necessary to specify a viewbag for state dropdownlist, since i am binding my state dropdownlist using json data so i don't need any viewbag or viewdata.

Thanks
Posted

1 solution

 
Share this answer
 
Comments
bhaveshgediya 7-Apr-15 2:46am    
If i am using @Html.Dropdownlist Helper instead of <select></select> then is there any solution ?,
King Fisher 7-Apr-15 2:48am    
In this article he used HTML helpers Only, Did u see that? Please i try this.
bhaveshgediya 7-Apr-15 3:14am    
I see it, he uses HTML helper for state dropdownlist but not district, for district he use html select tag, please reefer it, i don't want to use select tag instead of Helper

@Html.Label("State")
@Html.DropDownList("State", ViewBag.StateName as SelectList, "Select a State", new { id = "State" })
@Html.ValidationMessage("State", "*")

@Html.Label("District")
<select id="District" name="District"></select>
@Html.ValidationMessage("District", "*")

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900