Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disabling HTML.TextBoxFor()

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

like image 761
Ajax3.14 Avatar asked Jan 24 '12 22:01

Ajax3.14


2 Answers

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.

like image 179
Only Bolivian Here Avatar answered Sep 18 '22 10:09

Only Bolivian Here


You can try this in @Html.TextBoxFor

Html.TextBoxFor(m => m.Student.FirstName, new { id = "FirstName", ,@readonly="readonly" })
like image 32
Khan Avatar answered Sep 20 '22 10:09

Khan