0

How to have a condition work in razor, I have the code below, but it didn't work.

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

What is the correct syntax?

Thanks

Rj

RJ Uy
  • 377
  • 3
  • 10
  • 20
  • possible duplicate of [How to use ternary operator in razor (specifically on HTML attributes)?](http://stackoverflow.com/questions/4091831/how-to-use-ternary-operator-in-razor-specifically-on-html-attributes) – flq Jun 21 '13 at 19:33

2 Answers2

0

You're just missing some parentheses:

<span id="tab1" class="@(TempData["CurrentTab"] == "tab1" ? "ListTag ActiveTag" : "ListTag")">@MyAccountRes.VTxt_BasicInformation</span>                        
Ben Reich
  • 16,222
  • 2
  • 38
  • 59
0

Try this

<span id="tab1" class="@(TempData["CurrentTab"] == "tab1" ? "ListTag ActiveTag" : "ListTag")">@MyAccountRes.VTxt_BasicInformation</span> 
Satpal
  • 132,252
  • 13
  • 159
  • 168