I follow this guide:
http://www.dotnetexpertguide.com/2012/06/cascading-dropdown-knockoutjs-aspnet.html
The provided project works like a charm. It can be downloaded here: http://files.dotnetexpertguide.com/download.aspx?key=cascadingddlknockoutjs
The question is, I canโt understand how to change the view, so that another window for choosing a city appears and its contents change according to the selected state?
Writing another model for the city and actions in the controller to get the cities by state identifier is pretty straight forward, but I donโt understand how to change the view code and JS to make it work.
So the code to represent:
<p> <b>Select Country :</b> @Html.DropDownList("ddlCountry", ViewBag.Country as SelectList,"Select...", new { onchange = "FetchStates();" }) </p> <p data-bind="visible: states().length > 0"> <b>Select State :</b> <select data-bind="options: states, optionsText: 'StateName', optionsValue: 'StateId', optionsCaption: 'Choose...'"></select> </p> <script type='text/javascript'> function CascadingDDLViewModel() { this.states = ko.observableArray([]); } var objVM = new CascadingDDLViewModel(); ko.applyBindings(objVM); function FetchStates() { var countryCode = $("#ddlCountry").val(); $.getJSON("/Home/GetStates/" + countryCode, null, function (data) { objVM.states(data); }); } </script>
Any help is greatly appreciated.
source share