Usually, the loops in asp.net MVC razor view
will work the same as other programming languages. In the razor, we can define loop inside or outside code block and so we can use the same looping concept for assign value, define condition and increment or decrement value.
The syntax of for loop in asp.net MVC Razor view engine is given below
@for (int i = 0; i < 5; i++)
{
//Code Block
}
The example of for loop in MVC razor view is given:-
<h2>For loop</h2>
Output:-<br/>
@for (int i = 0; i < 5; i++)
{
@i<br/>
}
Output
The output of for loop example in asp.net MVC Razor view engine is given below
Output:-
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.
Usually, the loops in asp.net MVC razor view will work the same as other programming languages. In the razor, we can define loop inside or outside code block and so we can use the same looping concept for assign value, define condition and increment or decrement value.
The syntax of for loop in asp.net MVC Razor view engine is given below
The example of for loop in MVC razor view is given:-
Output
The output of for loop example in asp.net MVC Razor view engine is given below