2017-03-16 42 views
0

我有兩個不同的表,如果來自我的web應用程序的條件令牌爲真,否則顯示不同的表。我不知道如何正確包裹我的HTML內剃刀Razor IF/ELSE顯示HTML表

@if ("[HasRole:Administrators]" == "true") 
{ 
<table width="200" border="1"> 
    <tbody> 
    <tr> 
     <td>MY 1st TABLE</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    </tbody> 
</table> 
} 
else if ("[HasRole:Recruiter]" == "true") 
{ 
<table width="200" border="1"> 
    <tbody> 
    <tr> 
     <td>MY 2nd TABLE</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    <tr> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
     <td>&nbsp;</td> 
    </tr> 
    </tbody> 
</table> 
} 

回答

1
@if (User.IsInRole("Administrators")) 
{ 
    <table width="200" border="1"> 
     <tbody> 
     <tr> 
      <td>MY 1st TABLE</td> 
      <td>&nbsp;</td> 
      <td>&nbsp;</td> 
     </tr> 
     <tr> 
      <td>&nbsp;</td> 
      <td>&nbsp;</td> 
      <td>&nbsp;</td> 
     </tr> 
     <tr> 
      <td>&nbsp;</td> 
      <td>&nbsp;</td> 
      <td>&nbsp;</td> 
     </tr> 
     </tbody> 
    </table> 
} 
else if (User.IsInRole("Recruiter")) 
{ 
    <table width="200" border="1"> 
     <tbody> 
     <tr> 
      <td>MY 2nd TABLE</td> 
      <td>&nbsp;</td> 
      <td>&nbsp;</td> 
     </tr> 
     <tr> 
      <td>&nbsp;</td> 
      <td>&nbsp;</td> 
      <td>&nbsp;</td> 
     </tr> 
     <tr> 
      <td>&nbsp;</td> 
      <td>&nbsp;</td> 
      <td>&nbsp;</td> 
     </tr> 
     </tbody> 
    </table> 
}