views:

1110

answers:

4

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)%>
+4  A: 
<%= Html.TextBoxFor(m => Model.Events.Subscribed[i].Action, new {readonly=true})%>
Matt Dearing
+1  A: 

Hey,

Using the example of @Hunter, in the new { .. } part, add readonly = "readonly", I think that will work.

Brian
+5  A: 
<%= Html.TextBoxFor(m => Model.Events.Subscribed[i].Action, new { @readonly = true })%>
Dan
+2  A: 
<%= Html.TextBoxFor(model => Model, new Dictionary<string, object>(){{"readonly", "true"}}) %>

Do realize that this is not a "secure" way to do this as somebody can inject javascript to change this.

Jaxidian