[ACCEPTED]-Setting visibility of a textbox in MVC3 Razor view engine-asp.net-mvc-2

Accepted answer
Score: 16

This will change the display type based 2 on your bool Model.EnableCompanyName :)

Hope 1 it helps!

@{
String displayMode = (Model.EnableCompanyName) ? "inline" : "none";
@Html.TextBox("CompanyName", "", new { style = "display:" + displayMode + ";" })
}
Score: 8

It's nothing to do with razor as such. visible is 3 not a valid attribute for an input element (which 2 is what Html.TextBox will be generating). You 1 need

@Html.TextBox("CompanyName", "", new { style = "display:none;" })

See this example here:

http://jsfiddle.net/QxSpU/

Score: 3

Updated:

@Html.TextBox("CompanyName", "", new { style = Model.EnableCompanyName ? "display:inline" : "display:none" })

0

Score: 1

Try this:

@Html.TextBox("CompanyName", "", new {Style= Model.EnableCompanyName ? "visibility:visible" : "visibility:hidden"  })

0

More Related questions