Рули внутри MVC Razor view - PullRequest
       9

Рули внутри MVC Razor view

0 голосов
/ 04 сентября 2018

Я использую руль внутри бритвы в приложении ASP.NET MVC.

У меня есть ситуация, когда я должен использовать условие руля, если внутри условия другого бритвы что-то вроде ниже.

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>

Я знаю, что одна альтернатива - получить все значения, необходимые для условий внутри json, передаваемых на руль, и использовать его с условиями руля в шаблоне. Но я хочу использовать Razor везде, где это возможно.

Есть ли способ сделать это?

Примечание. Я попытался выполнить поиск в хранилище, но этот вопрос не является дубликатом!

1 Ответ

0 голосов
/ 04 сентября 2018

Использование тега <text> в 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>
...