razor syntax - foreach loop
@foreach (string s in "1,2,3".Split(',')) {
s is equal to @s<br/>
}
I want to spit out: s is equal to 1 s is equal to 2 s is equal to 3
But I'm getting all sorts of errors because Visual Studio thinks that what is between the {}'s is code, but I want it to be markup.
Solution 1:
Just saw this on ScottGu's blog this morning: use @:
before that line:
@foreach (string s in "1,2,3".Split(',')) {
@: s is equal to @s<br/>
}
Alternately, use the <text />
tag:
@foreach (string s in "1,2,3".Split(',')) {
<text>s is equal to @s<br/></text>
}
Solution 2:
Scott Guthrie just answered that this morning.
Change it to
@foreach (string s in "1,2,3".Split(',')) {
@: s is equal to @s<br/>
}