繁体   English   中英

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

[英]The parameters dictionary contains a null entry for parameter 'SolutionArchitectID' of non-nullable type 'System.Int32'

不知道我创建的下拉列表是否正在发送选定的值。 我是否缺少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表中要更新的字段。

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的价值?
  • 是否以表格形式寄回?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM