C# 多条件下的三元算子

C# 多条件下的三元算子,c#,asp.net,asp.net-mvc-4,ternary-operator,logical-operators,C#,Asp.net,Asp.net Mvc 4,Ternary Operator,Logical Operators,我在c#中有一个if条件 但是我尝试了这个代码 <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.Rep

我在c#中有一个if条件

但是我尝试了这个代码

<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>

但它不起作用。你能为我的错误给出正确的解决办法吗?

试试这个

@Html.ActionLink(item.ReportTitle, "GetPdf", "Report", new { report = item.ReporSubCategoryId }, 
 new { @style = "display:" 
  (item.ReporSubCategoryId == 1 || item.ReporSubCategoryId == 2 || item.ReporSubCategoryId == 3 || item.ReporSubCategoryId == 4)
   ? "block" : "none" }
})
它会根据您的情况添加“块”/“无”

(item.ReporSubCategoryId == 1 || item.ReporSubCategoryId == 2 || item.ReporSubCategoryId == 3 || item.ReporSubCategoryId == 4)
试试这个

@Html.ActionLink(item.ReportTitle, "GetPdf", "Report", new { report = item.ReporSubCategoryId }, 
 new { @style = "display:" 
  (item.ReporSubCategoryId == 1 || item.ReporSubCategoryId == 2 || item.ReporSubCategoryId == 3 || item.ReporSubCategoryId == 4)
   ? "block" : "none" }
})
它会根据您的情况添加“块”/“无”

(item.ReporSubCategoryId == 1 || item.ReporSubCategoryId == 2 || item.ReporSubCategoryId == 3 || item.ReporSubCategoryId == 4)

你的意思是说链接已被隐藏,但它仍会占用页面中的空间。我说的对吗?这肯定是一个混乱。看到这个可见性了吗:隐藏隐藏了元素,但它仍然占据了布局中的空间。显示:无从文档中完全删除元素。它不占用任何空间,即使源代码中仍然有它的HTML。-正如你的意思是说,链接已被隐藏,但它仍然消耗页面中的空间。我说的对吗?这肯定是一个混乱。看到这个可见性了吗:隐藏隐藏了元素,但它仍然占据了布局中的空间。显示:无从文档中完全删除元素。它不占用任何空间,即使源代码中仍然有它的HTML。-根据