When dropdownlitFor is disabled , value always passed as 0
Asked Answered
S

1

1

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.

Spaak answered 18/12, 2013 at 5:25 Comment(0)
F
2

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" })
Frisette answered 18/12, 2013 at 6:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.