I'm trying to make use of the onChange event for my dropdownlist in my ASP.NET MVC project, althought it is not working.
The view, containing the form, looks like this:
@using (Ajax.BeginForm("Action", "Controller",
new AjaxOptions
{
HttpMethod = "POST",
UpdateTargetId = "pages",
InsertionMode = InsertionMode.Replace
}))
{
@Html.DropDownListFor(m => m.SelectedFrom, Model.ChangeFrom, new { onChange = "this.form.submit();" })
}
<div id="pages"></div>
With the code above, onChange fires when selecting an item in the dropdownlist as expected. Although it's not making use of ajax, it is simply redirecting me to a new page, instead of just updating/filling the "pages-Div".
Although...
If I delete the onChange event for the dropdownlist and add a simple submit button, like this:
@using (Ajax.BeginForm("SelectedUser", "ReplaceName",
new AjaxOptions
{
HttpMethod = "POST",
UpdateTargetId = "pages",
InsertionMode = InsertionMode.Replace
}))
{
@Html.DropDownListFor(m => m.SelectedFrom, Model.ChangeFrom)
<input type="submit" value="GO" />
}
it uses Ajax and only reloads the "pages-Div".
Am I missing something?
Regards, Chris