我正在尝试渲染这样的东西:
<thead ng-init="isDoctor = @(User.IsInRole("Doctor"))">
我希望它是“isDoctor = true|false”(我的服务器端代码呈现此模板返回 PartialView),顺便说一句,我总是收到这样的错误:语法错误: token “未定义”不是主表达式从 [isDoctor = at Error ()] 开始的表达式 [isDoctor =] 的列为空。那么,这是什么原因呢?
最佳答案
试试这个方法:
<thead ng-init="isDoctor = @(User.IsInRole("Doctor") ? "true" : "false")">
因为 C# bool 值首字母大写:
<thead ng-init="isDoctor = True|False">
True
或 False
未定义
关于javascript - 带有 Razor 表达式的 ng-init,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20563579/