Best practice for handling cascading dropdowns of other postback scenarios in ASP.NET MVC
I've seen several examples of handling cascading dropdowns in ASP.NET MVC using jQuery and Ajax. Of course, this requires javascript to be enabled. Assuming javascript is disabled which would be the best method for handling cascading dropdowns.
Here is a real scenario of an asp.net webform I am developing for an inventory application for the company I work for. On a webpage, I have cascading dropdowns. In this example, let's say the Car Makes dropdown menu and the car model that depends on the selected Car Make. Also, in this form, I have a custom control that implements a search function so that the user can enter a city and / or state, select a search, and select a customer from the gridview, which fires an event to store the customer ID in a field for the current web order -page. I am not using javascript on this page. The dropdown menu starts postback and reloads the dropdowns in the second dropdown. The search user control triggers a postback,when the user clicks the Find button and when the user selects a customer from the grid.
How would this be handled in MVC? Will postbacks in my example equal actions in MVC? Will there be an action to change Car Make? Search action? Action to select from gridview?
I'm with a script where I have three dropdown menus and the value of each depends on the value of the previous one.
I know whenever a form is submitted it will go to a specific ActionName and by default it will be the same as the aspx page name, so if it is Index.aspx when it is submitted it calls the Index () method sitting in its controller.
The above behavior was causing a little problem, so
From:<%=Html.DropDownList("From", (SelectList)ViewData["From"], new { onchange = "this.form.action='Index'; this.form.submit();" })%>
To :<%=Html.DropDownList("To", (SelectList)ViewData["To"], new { onchange = "this.form.action='GetTo'; this.form.submit();" })%>
I first changed the name of the action to "GetTo" and then I posted the data, so it will jump to the controller's GetTo method, not Index ().
Here I am using javascript to change the name of the action and submit the form.
Hope this helps.
a source to share