Setting visibility of a textbox in MVC3 Razor view engine

╄→гoц情女王★ 提交于 2019-12-03 13:46:04

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/

(EDITED)

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!