Reputation: 9295
I got two drop down in a MVC Razor-View:
@Html.DropDownListFor(x => x.SelectedPrefix, Model.GetAssignablePrefixes() , new { @id = "prefixDropDown" })
@Html.DropDownListFor(x => x.SelectedSuffix, Model.GetAssignableSuffixes(Model.SelectedPrefix) , new { @id = "suffixDropDown" })
Selection of the first dropdown should change the content of the second dropdown depending of the value selected in the first dropdown. (Therefor the method GetAssignableSuffixes(Model.SelectedPrefix) is called)
As there are quite complex calculations, I do not want put all the logic into a JavaScript-method
I've found some "quite" simular questions here at SO, but not with DropDownListFor. Is there an approach fior that?
Upvotes: 0
Views: 323
Reputation: 18155
DropDownListFor is evaluated on the server when the page is first rendered. You're going to have to do this at least partially client-side. You could push the calculations onto the server by doing an AJAX call when the first dropdown changes and then populate the second dropdown with the results returned by the AJAX call.
Upvotes: 2