When dropdownlitFor is disabled , value always passed as 0

若如初见. 提交于 2019-12-11 11:39:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!