13

I have a view in MVC3 with a TextBoxFor bound to my model like so:

<%=Html.TextBoxFor(m => m.SomeProperty, new { @readonly = "readonly" }) %>

How could I change this to be a textbox which would have style="display: none;" by default?

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
Stian
  • 1,261
  • 2
  • 19
  • 38

3 Answers3

32

Not sure what you mean by default, but you could add the style attribute:

<%= Html.TextBoxFor(m => m.SomeProperty, new { style = "display: none;" }) %>

or:

<%= Html.TextBoxFor(m => m.SomeProperty, new { @class = "hidden" }) %>

and in your CSS file:

.hidden {
    display: none;
}
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
2
Html.TextBoxFor(m => m.SomeProperty, new { @readonly = "readonly", @hidden="true"})
4b0
  • 21,981
  • 30
  • 95
  • 142
Piauhy
  • 21
  • 1
1
<%= Html.HiddenFor(m=> m.SomeProperty, new { @readonly = "readonly" }) %>
JimbobTheSailor
  • 1,441
  • 1
  • 12
  • 21