我在 MVC View 中有一个下拉列表。在选择更改下拉列表时,我想在 Controller 中调用特定的操作方法。
我所做的是这样的:
<%=Html.DropDownList("ddl", ViewData["AvailableList"] as SelectList,
new { onchange = "this.form.action='MyMethod';this.form.submit();" })%>
一切都在编译。但是当我更改下拉选择时会引发运行时异常,如
"Microsift JScript Runtime Error : Object doesn't support property or method"
如何重定向到列表选择更改事件的特定操作?
如何将参数传递给此操作方法?
最佳答案
你的方法应该有效。您遇到的问题是您对 this
的使用在您的 onchange
事件无效。尝试更换您的 this.form
像这样的引用:
<%= Html.DropDownList(
"ddl", ViewData["AvailableList"] as SelectList,
new { onchange = @"
var form = document.forms[0];
form.action='MyMethod';
form.submit();"
} ) %>
关于asp.net-mvc - 在 MVC 中对下拉列表选择调用特定操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2213055/