【发布时间】:2017-12-13 15:07:17
【问题描述】:
我有以下视图Board.cshtml,我想根据DropDownListFor 的事件呈现部分视图MessagesBoard.cshtml。
Boards.cshtml
<script>
$(function () {
debugger
$("#selected_listBulletinBoardsMessages").change(function (e) {
alert($(this).val());
var val = $(this).val();
$("#updateBulletMessagesView").load("UpdateBoardMessages/", { listBulletinBoardsMessages: val });
});
});
</script>
<div>
@Html.DropDownListFor(model => model.listBulletinBoardsMessages, Model.listBulletinBoardsMessages.Select(b => new SelectListItem() { Value = b.Department, Text = b.Department }), "All Departments",
new { @class = "form-control",
id = "selected_listBulletinBoardsMessages"
})
</div>
<div id="updateBulletMessagesView">
@Html.Partial("MessagesBoard")
</div>
Controller 方法:UpdateBoardMessages 没有从 jQuery 脚本发送的 val 的值。
public ActionResult UpdateBoardMessages(string val)
{
val = val; //NULL??
..
return PartialView("MessagesBoard.cshtml");
}
我做错了什么?
【问题讨论】:
-
你的控制器动作被调用了吗?
-
您将变量作为 listBulletinBoardsMessages 而不是 val 传递。
-
@EhsanSajjad 是的。
-
@Fran 你的建议是:“val”而不是“{listBulletionBoardsMe:val}”?如果是这样的话。它也不起作用。
-
这段代码还有其他问题。请参阅 Ehsan 的回答。加载 URL 中缺少控制器。注意他没有在他传递 val 的 url 中传递 listBulletinBoardsMessages。
标签: c# jquery ajax asp.net-mvc http-post