如何在剃刀视图中使用三元运算符? [英] How to use ternary operator in razor view?
本文介绍了如何在剃刀视图中使用三元运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用MVC 4剃刀视图.如果"ERAGOGType"为"None",则我想在此禁用文本框,否则,如果值不是"None",则将其禁用
I am using MVC 4 razor view . here i want to disable the textboxfor if the "ERAGOGType" is "None" else if the value is not "None" then enable it
我的剃刀代码
@{
if ((Model.ERAGOGType == "None"))
{
@Html.LabelFor(model => model.ERAGOGCode)
@Html.TextBoxFor(model => model.ERAGOGCode, new { @disabled = true })
}
else
{
@Html.LabelFor(model => model.ERAGOGCode)
@Html.TextBoxFor(model => model.ERAGOGCode)
}}
如何通过使用三元运算符来实现此目的?请帮助
How can i achieve this by using a ternary operator ? plz help
预先感谢
推荐答案
您可以尝试:
@Html.TextBoxFor(model => model.ERAGOGCode, Model.ERAGOGType == "None" ? new { @disabled = true } : null)
这篇关于如何在剃刀视图中使用三元运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文