@foreach (string s in "1,2,3".Split(',')) {
s is equal to @s<br/>
}
我想吐出来:s等于1 s等于2 s等于3
但我收到了各种各样的错误,因为Visual Studio认为{}之间的是代码,但我希望它是标记。
发布于 2010-12-17 00:32:09
我刚刚看到了这个on ScottGu's blog this morning:在该行之前使用@:
:
@foreach (string s in "1,2,3".Split(',')) {
@: s is equal to @s<br/>
}
或者,使用<text />
标记:
@foreach (string s in "1,2,3".Split(',')) {
<text>s is equal to @s<br/></text>
}
发布于 2010-12-17 00:32:45
Scott Guthrie just answered that this morning。
将其更改为
@foreach (string s in "1,2,3".Split(',')) {
@: s is equal to @s<br/>
}
发布于 2010-12-17 00:33:35
@foreach (string s in "1,2,3".Split(',')) {
<text>s is equal to </text>@s<br/>
}
我认为这是因为你正在分析括号外的文本,所以Razor认为它是代码,试着使用上面的razor text标签,这与@:完全相同,但(至少对我来说)更直观(它不会解析标签)
https://stackoverflow.com/questions/4463000
复制相似问题