cascading dropdownlist in mvc 2 without jquery or json
I am new to ASP.NET MVC 2. In my project, there are two select
s: one that contains a list of countrie开发者_C百科s and another that should contain the states/provinces/etc for the country selected in the previous select
.
Is there any possibility to create a cascading select
without using any client scripting?
There's nothing out of the box for this; you simply have to check the posted form data for the entry in the country selection, and then load the model for the states. You may be able to make it more convenient using Html.Action and render the states list as a partial view...
HTH.
Without using JavaScript, you're not going to be able to have the states select
update its content automatically after an option is selected in the countries select
. You'll need an input type="submit"
somewhere that the user will have to press after selecting a country to POST the form, and return, with the rest of the ViewData, the list of states with which to populate the states select
.
Of course, when that POST occurs, you'll have to figure out if a state wasn't selected, and if so, return the ViewResult with the proper ViewData without doing anything else that would usually occur when the form is POSTed.
(If anyone is thinking "But WebForms can do this!", it's because it does it with JavaScript. :))
精彩评论