ASP.Net mvc, loops are work in Razor view as like in programming languages. We can define a loop inside or outside of the Razor engine block. We can use the foreach loop as like other loop to asign values to defined condition.
Syntax:
foreach( var item in RollNumber )
{
// statement here
}
Exp.-
<h2>ForEach loop example</h2>
Output:-<br/>
@{
var Number= Enumerable.Range(0,5);
foreach (var item in Number)
{
@item<br/>
}
}
Output :
ForEach loop example
Output:-
0
1
2
3
4
5
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
ForEach loop in asp.net MVC:
ASP.Net mvc, loops are work in Razor view as like in programming languages. We can define a loop inside or outside of the Razor engine block. We can use the foreach loop as like other loop to asign values to defined condition.
Syntax:
Exp.-
Output :