When dropdownlitFor is disabled, the value is always passed as 0

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 to pass a value that is already stored in objTicket.DepartmentId ?

If I change remove disabled = "disabled", I get the correct value.

+1
html5 razor asp.net-mvc-4 html.dropdownlistfor
source share
1 answer

Form fields are passed using names instead of identifiers. Values โ€‹โ€‹of disabled controls will not be sent by browsers. Place the @Html.HiddenFor field with the same name and different identifiers, as shown 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" }) 
+2
source share

All Articles