cascading html helper dropdownlistfor's in HTML razor for ASP.NET MVC

601 views Asked by At

Is there any convenient way to cascade multiple @Html.DropDownListFor ? i found >this< article that explained how to do it with partial views, but im not sure how to do it that way for multiple dropdown's cascading each other and i would like to keep things to 1 viewmodel too. The other implementation that i saw was by adding to a first @Html.DropDownListFor an @onchange javascript function that created more dropdownlists by calling an ajax function which returned the the options to add to the new drop down list, these new drop down lists were created using the html < select > tag, to which another @onchange javascript function was bound to keep cascading more of these. However i would like to know if there's a way of doing this by using only the DropDownListFor from the html helper and avoiding the html < select > tag.

I was trying to do something like this:

@Html.DropDownListFor(vm => vm.Var0, dataBase.fetchStartinOptions())
@Html.DropDownListFor(vm => vm.Var1, dataBase.fetchOptions(@Model.Var0))
@Html.DropDownListFor(vm => vm.Var2, dataBase.fetchOptions(@Model.Var1))

where "database.fetchOptions(x)" returns a "List < SelectListItem >"

But i dont know if that's possible at all, i was trying to find a way to do it with jquery and what not but couldnt find anything. The problem is that i cannot find a way to re-load the subsequent html.DropDownLists with the value from the previous one.

Thank you for your time.

--josepablo

0

There are 0 answers