Invoking particular action on dropdown list selection in MVC
Do you really need to submit the form? You could redirect:
onchange = "redirect(this.value)"
where redirect
is a custom defined function:
function redirect(dropDownValue) {
window.location.href = '/myController/myAction/' + dropDownValue;
}
Your approach should work. The issue you're encountering is your use of this
in your onchange
event is invalid. Try replacing your this.form
references with something like this:
<%= Html.DropDownList(
"ddl", ViewData["AvailableList"] as SelectList,
new { onchange = @"
var form = document.forms[0];
form.action='MyMethod';
form.submit();"
} ) %>