I have two different ways to use a DISABLED TextBoxFor
, which is:
@Html.TextBoxFor(u => u.Visibilidade, new { disabled = "disabled", @readonly = "readonly" })
and
@Html.TextBoxFor(u => u.Visibilidade, new { disabled = "disabled" })
ie. using or not readonly property
What is the difference, considering that a disabled field will not be changed any way?
Thanks in advance
The TextBoxes can be made ReadOnly by setting the HTML ReadOnly attribute using the HtmlAttributes parameter in Html. TextBox and Html. TextBoxFor helper functions.
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. Keep in mind that people can use a tool like Firebug or Dragonfly to edit the data and post it back.
EditorFor(model => model. userName, new { htmlAttributes = new { disabled = "disabled", @readonly = "readonly" } }) .
Usually you would use one or the other, not both.
Readonly allows users to focus on the textbox to copy text or trigger an event. Readonly fields will be posted with the form.
With a disabled field, users cannot give focus to the textbox and the field will NOT be posted with the form.
Which one you use depends on what you need to do with the field.
If you want to enable focus but don't want it posted, you can make it readonly, but override the name property.
@Html.TextBoxFor(u => u.Visibilidade, new { @readonly = "readonly", @Name = "" })
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