禁用dropdownlitFor时,值始终传递为0

时间:2013-12-18 05:25:40

标签: html5 asp.net-mvc-4 razor html.dropdownlistfor

这是我的dropdownlistFor

@Html.DropDownListFor(m => m.objTicket.DepartmentId, new SelectList(Model.objTicket.Departments, "DepartmentId", "Department"), 
"-- Select Department--", new { id = "Deptment"}, disabled="disabled")

如何传递已存储在objTicket.DepartmentId

中的值

如果我更改删除禁用=“禁用”,我会得到正确的值。

1 个答案:

答案 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" })