Setting visibility of a textbox in MVC3 Razor view engine
This will change the display type based on your bool Model.EnableCompanyName :)
Hope it helps!
@{
String displayMode = (Model.EnableCompanyName) ? "inline" : "none";
@Html.TextBox("CompanyName", "", new { style = "display:" + displayMode + ";" })
}
It's nothing to do with razor as such. visible
is not a valid attribute for an input
element (which is what Html.TextBox will be generating). You need
@Html.TextBox("CompanyName", "", new { style = "display:none;" })
See this example here:
http://jsfiddle.net/QxSpU/
Updated:
@Html.TextBox("CompanyName", "", new { style = Model.EnableCompanyName ? "display:inline" : "display:none" })