Invoking particular action on dropdown list selection in MVC

后端 未结 7 1776
时光取名叫无心
时光取名叫无心 2021-02-01 18:08

I have a dropdown list in an MVC view. On selection change of dropdown list I want to call specific action method in the controller.

What I have done on view is this :

7条回答
  •  无人及你
    2021-02-01 19:00

    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();" 
            } ) %>
    

提交回复
热议问题