问题
This is my dropdownlistFor
@Html.DropDownListFor(m => m.objTicket.DepartmentId, new SelectList(Model.objTicket.Departments, "DepartmentId", "Department"),
"-- Select Department--", new { id = "Deptment"}, disabled="disabled")
How can I pass the value which is already stored in objTicket.DepartmentId
?
If i change remove disabled ="disabled", i get my correct value.
回答1:
Form fields are submitted using Names instead of Ids. Disabled controls values wont be submitted by browsers. Place a @Html.HiddenFor
field with same name and different Ids as given below.
@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" })
来源:https://stackoverflow.com/questions/20650267/when-dropdownlitfor-is-disabled-value-always-passed-as-0