【发布时间】:2011-12-17 00:09:10
【问题描述】:
我有一个下拉列表,更改后应该刷新视图的模型。这是控制器:
public ActionResult Index()
{
//do something totally awesome
}
[HttpPost]
public ActionResult Index(int user)
{
//do something even more awesome with the new value selected from the drop down list
}
视图的相关部分:
<div id="selectuser" class="user-input">@Html.DropDownListFor(x => x.SelectedUser, Model.Users)</div>
以及处理下拉列表变化的jQuery:
$(function () {
$('#selectuser select').change(function () {
$.post('@Url.Action("Index", "Home")', { user: $(this).val() }, function (result) {
});
});
});
似乎一切正常,除了 jQuery 部分。显然, UrlAction(...) 是不正确的。当用户更改选择时,这是 MVC 尝试加载的 URL:http://localhost:5555/@Url.Action%28%22Index%22,%20%22Home%22%29
我希望 MVC 在选择更改时路由到控制器中的 HttpPost Index 操作。为什么没有呢?我该如何解决?
在这方面我完全是菜鸟 - 非常感谢您的帮助。
【问题讨论】:
标签: jquery asp.net-mvc-3