@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.
Generally, the loops in asp.net mvc razor view will work same as other programming languages. We can define loop inside or outside code block in the razor and use the same looping concept for assign value, define condition and increment, or decrement value.
Razor syntax is a simple programming syntax for embedding server-based code in a web page. In a web page that uses the Razor syntax, there are two kinds of content: client content and server code.
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> }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With