I develop a web application below ASP.NET MVC 4 with Razor Views.
I noticed now that SomethingID
is empty in the ViewModel after Postback (to the Controller)
if I only add the disabled
HTML attribute to DropDownListFor:
// SomethingID becomes 0:
@Html.DropDownListFor(m => m.SomethingID, Model.SomethingList, new { @disabled = "disabled" })
It doesn't happen if I remove the disabled
Attribute, SomethingID has the proper value then:
// SomethingID keeps its value (greater than 0):
@Html.DropDownListFor(m => m.SomethingID, Model.SomethingList)
Has someone experienced that problem already? At the moment, I try to solve the problem with jQuery, by storing the value in a HiddenFor field.
But my question would be: Is there a better solution? Is it intended behaviour from Microsoft that Dropdownlists shall forget everything as soon as they are disabled? Do I do a mistake? Is it a bug?
Remark: I have 5 Dropdownlists in my View, all 5 show the same behaviour.
Many thanks in advance!!!