Stian
Stian

Reputation: 1299

How can I set TextBoxFor to be hidden by default

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?

Upvotes: 14

Views: 66213

Answers (3)

Piauhy
Piauhy

Reputation: 41

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

Upvotes: 4

JimbobTheSailor
JimbobTheSailor

Reputation: 1613

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

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038920

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;
}

Upvotes: 33

Related Questions