参数字典包含参数' SolutionArchitectID'的空条目。非可空类型的System.Int32'

时间:2015-11-12 15:17:10

标签: c# asp.net drop-down-menu html-helper

不确定我创建的下拉菜单是否正在发送选定的值。我是否错过了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表中更新的字段。

1 个答案:

答案 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>
...
}

我认为对以下问题的回答会有所帮助

  • 您将如何获得SolutionArchitectID的价值?
  • 是否会以表格形式寄回?