不确定我创建的下拉菜单是否正在发送选定的值。我是否错过了DropDownList帮助器中的参数?
CreateDropDowns方法
List<SelectListItem> EmployeeList = new List<SelectListItem>();
foreach (Employee e in db.Employees)
{
EmployeeList.Add(new SelectListItem { Text = e.FirstName + " " + e.LastName, Value = e.SolutionArchitectID.ToString() });
}
ViewBag.EmployeeList = EmployeeList;
UpdateDetails方法
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult UpdateDetails(int SolutionArchitectID) {
Asset currAppRecord = db.Assets.Where(a => a.ApplicationID == ApplicationID).Single();
...
currAppRecord.SolutionArchitectID = SolutionArchitectID;
...
}
查看
@using (Html.BeginForm("UpdateDetails", "Atlas"))
{
...
<div class="form-group">
<label class="control-label col-md-2" for="Employees">Solution Architect</label>
<div class="col-md-10">
@Html.DropDownList("EmployeeList")
</div>
</div>
...
}
SolutionArchitectID是要在提交的db表中更新的字段。
答案 0 :(得分:0)
在using
中,没有名为SolutionArchitectID的Html控件。要成功提交表单,您需要传递SolutionArchitectID。如下面的代码所示。
@using (Html.BeginForm("UpdateDetails", "Atlas"))
{
...
<div class="form-group">
<label class="control-label col-md-2" for="Employees">Solution Architect</label>
<div class="col-md-10">
@Html.DropDownList("EmployeeList")
@Html.Hidden("SolutionArchitectID", <<PutHereSomeValue>>)
</div>
</div>
...
}
我认为对以下问题的回答会有所帮助