简体   繁体   中英

why I can't use @ in input:name with value in the back

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="a1@qu.ID" name="q@qu.ID"><label for="a1 @qu.ID">@qu.a1</label></li>

在此处输入图片说明

Because there is no space 1 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM