Html.TextBoxFor(m => m.Student.FirstName, new { id = "FirstName", disabled = "disabled" })
I wanted to disable the the text box so i used disabled attr as above and it worked but upon saving the form, the value loaded in above textbox turns to null.
any body have a idea of what is going on
Thanks
This is by design. Disabled inputs don't POST back to the server.
You can make the input 'read only' by using 'readonly'. This will let the data be POSTED back, but the user cannot edit the information in the traditional fashion.
<input type="text" name="foo" value="Some Value" readonly="readonly" />
Keep in mind that people can use a tool like Firebug or Dragonfly to edit the data and post it back. So keep on your toes and either make sure the data is the same, or better yet, just use the disabled attribute.
You can try this in @Html.TextBoxFor
Html.TextBoxFor(m => m.Student.FirstName, new { id = "FirstName", ,@readonly="readonly" })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With