我有一个下拉列表,用于从ViewBag获取数据。在视图中,它设置如下
@using (Html.BeginForm("CreateVoteType", "AlterVote", FormMethod.Post, new { id = "prefsForm", name = "prefsForm" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>New voting preference</h4>
<hr />
<p>Please select the type of vote you wish to change to @Html.DropDownListFor(model=>model.SelectedType, ViewBag.myList as SelectList, "Voting type", new { @class = "form-control", onchange = "SelectedIndexChanged()"})</p>
我的selectedindexchanged脚本中只有一行
document.prefsForm.submit();
我尝试做的是当我更改下拉列表中的选项时,它会向控制器反刍(这不起作用 - 如果我添加了selectedindexchanged,则不会被命中alert.Show("hello!");
到函数,它从不显示),会创建一个ViewBag.alertMessage (string)
和一个ViewBag.AlertShow (bool)
,然后传播到视图中。
我处理变更的控制器如下所示
[HttpPost]
public PartialViewResult AlterVote(Dropdown dropType)
{
ChangeBoilerPlate(dropType.SelectedType);
return PartialView(dropType);
}
(ChangeBoilerPlate设置AlertShow和alertMessage)
任何出错的想法?