How to set TextBoxFor to hide by default

I have a view in MVC3 with TextBoxFor tied to my model as follows:

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

How can I change this as a text box that will have the style = "display: none;" default?

+8
source share
2 answers

Not sure what you mean by default, but you can 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; } 
+23
source
 <%= Html.HiddenFor(m=> m.SomeProperty, new { @readonly = "readonly" }) %> 
0
source

Source: https://habr.com/ru/post/1390189/


All Articles