部分视图中的下拉菜单更改触发了ChildAction [英] ChildAction triggered on dropdown change in partial view
问题描述
我想在下拉菜单的onchange
事件上在本地控制器上触发ChildAction
.下拉菜单位于_Layout.cshtml
.
是否可以在javascript上实现?
这是我目前的代码.
$('#langDropdown').change(function() {
var lang = $(this).val();
alert(lang);
});
这是我的下拉菜单:
@Html.DropDownList("Language", ViewData["Languages"] as SelectList,
new { id = language })
它不是任何形式的内容.任何建议我该怎么做.谢谢!
注意:我只是将警报用于测试目的.
您应将下拉列表放在一种形式,该形式将POST请求提交到单独的操作(此操作可以与子操作具有相同的名称).>
如我在上一个答案中所述,POST操作将希望重定向回原始URL.评论).
I want to trigger a ChildAction
on the Home Controller on the onchange
event of a dropdown. The dropdown is located at the _Layout.cshtml
.
Is it possible to do it on javascript?
Here is my code as of the moment.
$('#langDropdown').change(function() {
var lang = $(this).val();
alert(lang);
});
And here is my dropdown:
@Html.DropDownList("Language", ViewData["Languages"] as SelectList,
new { id = language })
It not inside of any form. Any suggestion how can I do it. Thanks!
Note: I just use alert for testing purposes.
You should put your dropdown in a form that submits a POST request to a separate action (this action can have the same name as the child action).
The POST action would want to redirect back to the original URL, as I explained in my previous answer (see also comments).
这篇关于部分视图中的下拉菜单更改触发了ChildAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!