Invoking particular action on dropdown list selection in MVC

后端 未结 7 1781
时光取名叫无心
时光取名叫无心 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 18:47

    @Shimmy is there a way to do this as a one-liner, without defining the function in js?

    yes you can and here is the code for that:

    @Html.DropDownListFor(m => m.Name, new SelectList((System.Collections.IEnumerable)ViewBag.DropDownName, "Value", "Text"), new { @class = "form-control", onchange = "document.location.href = '/Home/Employee?c=' + this.options[this.selectedIndex].value;" })
    

提交回复
热议问题