Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set text box to readonly when using Html.TextBoxFor?

I have the following tag with a Html.TextBoxFor expression and I want the contents to be read only, is this possible?

<%= Html.TextBoxFor(m => Model.Events.Subscribed[i].Action)%> 
like image 878
AwkwardCoder Avatar asked Mar 29 '10 15:03

AwkwardCoder


People also ask

How do you make a TextBoxFor readonly?

The TextBoxes can be made ReadOnly by setting the HTML ReadOnly attribute using the HtmlAttributes parameter in Html. TextBox and Html. TextBoxFor helper functions.

How do I make a TextBox readonly in razor view?

Solution 1 In razor, everything is easy just add @readonly attribute to the code will do the needful.

What is the difference between using HTML TextBoxFor and HTML TextBox?

Both of them provide the same HTML output, “HTML. TextBoxFor” is strongly typed while “HTML. TextBox” isn't. Below is a simple HTML code which just creates a simple textbox with “CustomerCode” as name.


1 Answers

<%= Html.TextBoxFor(m => Model.Events.Subscribed[i].Action, new { @readonly = true })%> 
like image 163
Dan Avatar answered Sep 28 '22 01:09

Dan