ASP.NET MVC下拉列表视图包存储过程

时间:2018-12-20 18:34:36

标签: asp.net-mvc stored-procedures dynamic viewbag dropdownlistfor

我无法使用Viewbag从动态下拉列表中获取ID值,我正在使用存储过程来插入数据。 id的值来自动态下拉列表。

我认为我正在使用

$ unset XAUTHORITY
$ xhost add $DISPLAY . 123f
$ xhost +local:all
$ sudo xclock # or any graphical program needs sudoer 

在我的控制器中

@Html.DropDownList("DepartmentID", new SelectList(ViewBag.data, "depId", "depId"), "Department-ID")

1 个答案:

答案 0 :(得分:2)

您已将UI字段命名为DepartmentID

@Html.DropDownList("DepartmentID", new SelectList(ViewBag.data, "depId", "depId"), "Department-ID")

但是模型上的属性是depId。您的字段名称需要与绑定它们的模型的属性名称匹配:

@Html.DropDownList("depId", new SelectList(ViewBag.data, "depId", "depId"), "Department-ID")