Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-init with razor expression

I am trying to render the thing like this:

<thead ng-init="isDoctor = @(User.IsInRole("Doctor"))">

I expect it to be "isDoctor = true|false" (my server side code renders this template returning PartialView), btw I always get an error like: Syntax Error: Token 'undefined' not a primary expression at column null of the expression [isDoctor =] starting at [isDoctor = at Error ()]. So, what is the reason for that?

like image 602
starbeast Avatar asked Jan 30 '26 08:01

starbeast


1 Answers

Try this way:

<thead ng-init="isDoctor = @(User.IsInRole("Doctor") ? "true" : "false")">

Because C# boolean renders with capital first letter:

<thead ng-init="isDoctor = True|False">

And True or False is undefined

like image 179
karaxuna Avatar answered Feb 01 '26 23:02

karaxuna