2013-06-21 60 views
0

如何在剃刀上有條件工作,我有下面的代碼,但它沒有工作。剃刀中上課的條件

<span id="tab1" class="@TempData["CurrentTab"] == 'tab1' ? 'ListTag ActiveTag' : 'ListTag'">@MyAccountRes.VTxt_BasicInformation</span>       
<span id="tab2" class="@TempData["CurrentTab"] == 'tab2' ? 'ListTag ActiveTag' : 'ListTag'">@MyAccountRes.VTxt_DetailInformation</span> 
<span id="tab3" class="@TempData["CurrentTab"] == 'tab3' ? 'ListTag ActiveTag' : 'ListTag'">@MyAccountRes.VTxt_IconManagment</span> 
<span id="tab4" class="@TempData["CurrentTab"] == 'tab4' ? 'ListTag ActiveTag' : 'ListTag'">@MyAccountRes.VTxt_EducationInfomation</span> 
<span id="tab5" class="@TempData["CurrentTab"] == 'tab5' ? 'ListTag ActiveTag' : 'ListTag'">@MyAccountRes.VTxt_JobInfomation</span> 

什麼是正確的語法?

感謝

RJ

+0

的[如何在剃鬚刀使用三元操作可能重複(特別是對HTML屬性)?](http://stackoverflow.com/questions/4091831/how-to-use-ternary-operator-in-razor-specific盟友-ON-HTML的屬性) – flq

回答

0

試試這個

<span id="tab1" class="@(TempData["CurrentTab"] == "tab1" ? "ListTag ActiveTag" : "ListTag")">@MyAccountRes.VTxt_BasicInformation</span> 
0

你只是缺少一些括號:

<span id="tab1" class="@(TempData["CurrentTab"] == "tab1" ? "ListTag ActiveTag" : "ListTag")">@MyAccountRes.VTxt_BasicInformation</span>