Reputation: 45
I have really basic problem with razorpage in asp.net core. I can't use @variable in the below code:
<li><input type="radio" id="[email protected]" name="[email protected]"><label for="a1 @qu.ID">@qu.a1</label></li>
Upvotes: 1
Views: 59
Reputation: 17447
Because there is no space1 before the @
. Razor treats that as a single string.
For example, this razor:
@{
var val1 = "hello";
var val2 = "world";
}
<p>Let us say @val1 to Joe</p>
<p>The@val2 is large</p>
Renders to
Let us say hello to Joe The@val2 is large
https://dotnetfiddle.net/bWhYmd
You can fix that by wrapping the code after @
in parentheses.
<p>The@(val2) is large</p>
Will render to
Theworld is large
https://dotnetfiddle.net/BbeK2C
1 It's not strictly a "space"; realistic it's any non alphanumeric character, though I'm not sure exactly what the actual character set is.
Upvotes: 3