Razor IF / ELSE显示HTML表格

时间:2017-03-16 00:32:00

标签: asp.net-mvc html5 razor

如果我的网络应用程序中的条件标记为true,我有两个不同的表格,否则显示不同的表格。我不确定如何在剃刀内正确包装我的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 个答案:

答案 0 :(得分: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>
}