【发布时间】:2013-06-06 03:07:27
【问题描述】:
我在 c# 中有一个 if 条件
if (item.ReporSubCategoryId == 1 || item.ReporSubCategoryId == 2 ||
item.ReporSubCategoryId == 3 || item.ReporSubCategoryId == 4)
{
<a href="@Url.Action("GetPdf", "Report", new { report = item.ReporSubCategoryId })" >@item.ReportTitle</a>
}
如果条件改变,我想使用三元运算符?
使用显示和隐藏这个标签
(style='display:Myconditions?block:None')
<a href="@Url.Action("GetPdf", "Report", new { report = item.ReporSubCategoryId })" >@item.ReportTitle</a>
但我试试这段代码
<a style='display:" @item.ReporSubCategoryId == 1 || @item.ReporSubCategoryId == 2 || @item.ReporSubCategoryId == 3 || @item.ReporSubCategoryId == 4 ?block:None"'href="@Url.Action("GetPdf", "Report", new { report = item.ReporSubCategoryId })" >@item.ReportTitle</a>
但它不起作用。你能针对我的错误给出正确的解决方案吗?
【问题讨论】:
标签: c# asp.net asp.net-mvc-4 ternary-operator logical-operators