这是我的dropdownlistFor
@Html.DropDownListFor(m => m.objTicket.DepartmentId, new SelectList(Model.objTicket.Departments, "DepartmentId", "Department"),
"-- Select Department--", new { id = "Deptment"}, disabled="disabled")
如何传递已存储在objTicket.DepartmentId
?
如果我更改删除禁用=“禁用”,我会得到正确的值。
答案 0 :(得分:2)
使用名称而不是ID提交表单字段。浏览器不会提交已禁用的控件值。放置一个@Html.HiddenFor
字段,其中包含相同的名称和不同的ID,如下所示。
@Html.DropDownListFor(m => m.objTicket.DepartmentId, new SelectList(Model.objTicket.Departments, "DepartmentId", "Department"),Department--", new { id = "Deptment"}, disabled="disabled")
@Html.HiddenFor(m => m.objTicket.DepartmentId, new { id="Deptment2" })