asp.net-mvc 你如何在asp.net mvc中提交下拉列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/364505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-07 23:12:46  来源:igfitidea点击:

How do you submit a dropdownlist in asp.net mvc

asp.net-mvcdrop-down-menuonchange

提问by maxnk

<% using (Html.BeginForm() { %>

  <%=Html.DropDownList("TopItemsList", ViewData["ListData"], new { onchange="[???]" })%>

<% } %>

In the above example, what value should you set onchange to? Or, how do you get the correct form?

在上面的例子中,你应该将 onchange 设置为什么值?或者,您如何获得正确的表格?

Is there any difference with Ajax.BeginFrom?

与 Ajax.BeginFrom 有什么区别吗?

回答by maxnk

try this:

尝试这个:

<%=Html.DropDownList("TopItemsList", ViewData["ListData"], new { onchange="this.form.submit();" })%>

Every form element in the has a "form" property that is pointed to the form that contains this element.

中的每个表单元素都有一个指向包含该元素的表单的“表单”属性。

Yes, using "Html." and "Ajax." has a difference. Ajax. means that partial page update will be used and the whole page will not be reloaded.

是的,使用“HTML”。和“阿贾克斯”。有区别。阿贾克斯。意味着将使用部分页面更新并且不会重新加载整个页面。

回答by Lee Smith

Why are you mixing your html with javascript??

你为什么把你的 html 和 javascript 混合在一起??

Delete the onchange attribute and add some JQuery:

删除 onchange 属性并添加一些 JQuery:

$("#TopItemsList").change(function () {

    $("input[type=submit]").click();

});