【发布时间】:2018-09-04 00:48:42
【问题描述】:
我在 ASP.NET MVC 应用程序的 razor 视图中使用把手。
我有一种情况,我必须在剃须刀的 else 条件中使用车把的 if 条件,如下所示。
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。
有什么办法可以做到吗?
注意:我尝试在存储库中搜索,但这个问题似乎不是重复的!
【问题讨论】:
-
你现在做的有什么问题?
-
Razor 视图无法编译。 {{#if UserCanSetClosed}} 行中的“#”被视为预处理器指令。准确地说,else 部分中的代码被视为 C# 代码而不是把手。
标签: c# .net asp.net-mvc razor handlebars.js