Asp.net-Mvc

Razor 視圖中的內聯 If

  • June 24, 2014

在我的控制器中,我有內聯 If 語句:

ViewBag.NameSortParam = If(String.IsNullOrEmpty(sortOrder), "Name desc", "")

在我看來,如果出現以下情況,我似乎無法使用內聯:

@Code
   If(True, true, true)
End code

它說,“If 必須以匹配的 End If 結尾。” 如果在這裡,為什麼我不能使用內聯?謝謝。

嘗試

@Code
   @(If(True, true, true))
End Code

你可以使用這樣的東西:

  @(true? "yes": "no") 

引用自:https://stackoverflow.com/questions/12391853