The loops in asp.net MVC razor view will also work the same as other programming languages. But in razor, we can define loop
inside or outside code block and we can use the same foreach looping concept to assign value, define the condition.
The syntax of using foreach loop in asp.net MVC razor view is given below
foreach (var item in marks)
{
//Code Block
}
The example of using foreach loop in asp.net MVC razor view is shown below
<h2>ForEach loop</h2>
Output:-<br/>
@{
var marks = Enumerable.Range(0,5);
foreach (var item in marks)
{
@item<br/>
}
}
The output of Foreach Loop in MVC
The output of foreach loop example in asp.net MVC Razor view engine
0 1 2 3 4
Join MindStick Community
You need to log in or register to vote on answers or questions.
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.
The loops in asp.net MVC razor view will also work the same as other programming languages. But in razor, we can define loop inside or outside code block and we can use the same foreach looping concept to assign value, define the condition.
The syntax of using foreach loop in asp.net MVC razor view is given below
The example of using foreach loop in asp.net MVC razor view is shown below
The output of Foreach Loop in MVC
The output of foreach loop example in asp.net MVC Razor view engine