在MVC3剃刀视图引擎设置文本框的可见性 [英] Setting visibility of a textbox in MVC3 Razor view engine

查看:82
本文介绍了在MVC3剃刀视图引擎设置文本框的可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的MVC 3,剃刀视图引擎。
我想设置在运行时按在我的视图模型值的文本框的可见性。

I am new to MVC 3, razor view engine. I want to set the visibility of a textbox at runtime as per the value in my viewmodel.

但低于code不工作。

But the below code is not working.

<td>
    @Html.TextBox("CompanyName", "", new { visible = "false" })
</td>

以上一旦code开始工作,我可以把 @ Model.EnableCompanyName 到位假。

所以,请帮我整顿上述code。

So please help me in rectifying the above code.

推荐答案

根据您的布尔Model.EnableCompanyName这将改变显示类型:)

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

希望它帮助!

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

这篇关于在MVC3剃刀视图引擎设置文本框的可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆