2011-11-30 84 views
2

我正在用剃刀生成菜單,並且顯示正常時出現問題。這是給我的問題行:菜單中的剃刀語法

<li @topNavCurrentCount == @topNavCount ? "class=last" : @string.Empty><a href="@node.Url.Replace("~/","/").Replace(".aspx","")">@node.Title</a> 

它呈現HTML這樣的:

<li {1 == 7 ? "class=last" : ;}><a href="/Home">Home</a> 

我知道IM接近得到它,但我不能看到它。

回答

2

嘗試在if語句周圍放置括號。

<li @(topNavCurrentCount == topNavCount ? "class=last" : string.Empty)> 

@旁邊的一個變量會打印出值

1

我認爲以下可能的工作(將括號中的語句):

<li @(topNavCurrentCount == topNavCount ? "class=last" : string.Empty)><a href="@node.Url.Replace("~/","/").Replace(".aspx","")">@node.Title</a>