如何使用在 jsRender 模板中的视图页面中声明的 C# 变量

How to use C# variables declared in View page inside a jsRender template

我需要使用在 js 呈现模板内的 cshtml 视图页面中声明的变量。可能吗??下面是我的代码。

@{
bool isAdmin = false;
}

<script type="text/x-jsrender" id="ProjectStatus">
{{if Status == 1 && isAdmin}}
<span class="status status-open">{{:Status}}</span>
{{/if}}
</script>

提前致谢。

Dinesh.

要在 Javascript 中使用 C# 变量,只需添加 @:

{{if Status == 1 && '@isAdmin' == 'True'}}
     <span class="status status-open">{{:Status}}</span>
{{/if}}