I want to disable a textbox in the view. So I use following code:
<%= Html.TextBox("ID", Model.ID, new { readonly="true" })%> or
<%= Html.TextBox("ID", Model.ID, new { enable="false" })%> Both of them don't work. what's the solution?
TextBoxFor(m => m.ID, new { @readonly = "readonly" }) it works as expected.
The TextBoxes can be made ReadOnly by setting the HTML ReadOnly attribute using the HtmlAttributes parameter in Html. TextBox and Html. TextBoxFor helper functions.
EditorFor(model => model. userName, new { htmlAttributes = new { disabled = "disabled", @readonly = "readonly" } }) .
Try
<%= Html.TextBox("ID", Model.ID, new { @readonly="readonly" })%> I'm not sure you have to use the overload with 4 parameters. You should be able to use the one with 3, but you need to append @ to the readonly since readonly is a keyword in C#. And setting @readonly to readonly is XHTML compliant.
Try
<%= Html.TextBox("ID", Model.ID, null, new { @readonly="true" })%> instead of
<%= Html.TextBox("ID", Model.ID, new { @readonly="true" })%> If you check the documentation, you can see that the third parameter is not htmlAttributes, as you probably expected.
You need to use the overload with four parameters.
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