'What is readonly for in a disabled TextBoxFor?

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



Solution 1:[1]

Note: If you want it to be disabled, but you do want the original value to be posted with the form, you can use a HiddenFor along with your TextboxFor (with id set to null so the browser console doesn't complain about duplicate ids):

@Html.TextBoxFor(u => u.Visibilidade, new { @disabled = "disabled"})
@Html.HiddenFor(u => u.Visibilidade, new { id = null });

This way, the value from the HiddenFor will be posted with the form, but the textbox will be displayed as disabled.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Taraz