C# MVC剃须刀视图中的把手

C# MVC剃须刀视图中的把手,c#,.net,asp.net-mvc,razor,handlebars.js,C#,.net,Asp.net Mvc,Razor,Handlebars.js,我在ASP.NETMVC应用程序的razor视图中使用把手 我有一个情况,我必须使用手柄的如果条件内的剃须刀的其他条件类似下面 Index.cshtml <script id="template" type="text/x-handlebars-template"> .... @if (CurrentUserRepository.IsInRoleEnums(RoleEnum.TPS_Administrator)) {

我在ASP.NETMVC应用程序的razor视图中使用把手

我有一个情况,我必须使用手柄的如果条件内的剃须刀的其他条件类似下面

Index.cshtml

<script id="template" type="text/x-handlebars-template">
       ....
      @if (CurrentUserRepository.IsInRoleEnums(RoleEnum.TPS_Administrator)) 
           {
               <i class="fas fa-trash-alt text-dark pointer" title="Delete this item" onclick="DeleteNotification({{NotificationId}})"></i>
           }
       else
           {
              //handlebars shown below doesn't work
              {{#if UserCanSetClosed}}
                 <i class="fas fa-trash-alt text-dark pointer" title="Delete this item" onclick="DeleteNotification({{NotificationId}})"></i>
              {{/if}}                    
           }
</script>

....
@if(CurrentUserRepository.IsInRoleEnums(RoleEnum.TPS_管理员))
{
}
其他的
{
//下面显示的把手不起作用
{{#如果UserCanSetClosed}
{{/if}
}
我知道另一种方法是获取传递给handlebar的json中的条件所需的所有值,并将其与模板中的handlebar条件一起使用。但我想尽可能使用剃须刀

有什么办法可以做到这一点吗

注意:我尝试在存储库中搜索,但这个问题似乎不是重复的

在Razor中使用
标记可能有助于视图引擎正确处理车把语法

请尝试以下示例代码:

<script id="template" type="text/x-handlebars-template">

  @if (CurrentUserRepository.IsInRoleEnums(RoleEnum.TPS_Administrator)) 
  {
    <text><i class="fas fa-trash-alt text-dark pointer" title="Delete this item" onclick="DeleteNotification({{NotificationId }})"></i></text>
  }
  else
  {
      //handlebars shown below doesn't work
          <text>{{#if UserCanSetClosed}}</text>
          <text><i class="fas fa-trash-alt text-dark pointer" title="Delete this item" onclick="DeleteNotification({{NotificationId}})"></i></text>
          <text>{{/if}}</text>
  }
</script>

@if(CurrentUserRepository.IsInRoleEnums(RoleEnum.TPS_管理员))
{
}
其他的
{
//下面显示的把手不起作用
{{#如果UserCanSetClosed}
{{/if}
}

您现在所做的有什么问题吗?Razor视图无法编译。第{{if UserCanSetClosed}行中的“#”被视为预处理器指令。准确地说,else部分中的代码被视为C#code,而不是handlebar。