剃刀语法 - foreach循环
问题描述:
@foreach (string s in "1,2,3".Split(',')) {
s is equal to @s<br/>
}
我要吐了出来: s等于1 s等于2 s等于3剃刀语法 - foreach循环
但我发现了各种因视觉误差的Studio认为{}之间的内容是代码,但我希望它是标记。
答
刚看到这个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>
}
答
Scott Guthrie just answered that this morning。
将其更改为
@foreach (string s in "1,2,3".Split(',')) {
@: s is equal to @s<br/>
}
答
@foreach (string s in "1,2,3".Split(',')) {
<text>s is equal to </text>@s<br/>
}
我想这是因为你在括号外的解析文本,以便剃刀想它的代码,请尝试使用上面的剃刀文本标签,这种分析完全一样@ :但(至少对我来说)更直观一些(它不会解析标签)
''对多行很好。 –
crush
2014-10-28 17:52:54