---
title: "How to use ForEach loop in asp.net MVC?"  
description: "How to use ForEach loop in asp.net MVC?"  
author: "Kalin"  
published: 2022-03-11  
updated: 2022-03-11  
canonical: https://www.mindstick.com/forum/156909/how-to-use-foreach-loop-in-asp-dot-net-mvc  
category: "asp.net mvc"  
tags: ["asp.net", "asp.net mvc"]  
reading_time: 1 minute  

---

# How to use ForEach loop in asp.net MVC?

How to use [ForEach loop in asp.net](https://answers.mindstick.com/qa/98063/how-to-use-foreach-loop-in-asp-dot-net-mvc-cshtml-file) [MVC](https://www.mindstick.com/forum/155803/define-cache-profile-in-mvc)?

## Replies

### Reply by Steilla Mitchel

**[ForEach loop](https://www.mindstick.com/forum/182/problem-in-getting-the-value-from-array-by-using-foreach-loop) in [asp.net MVC](https://www.mindstick.com/forum/155798/what-is-caching-in-asp-dot-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:

```
 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
```

\


---

Original Source: https://www.mindstick.com/forum/156909/how-to-use-foreach-loop-in-asp-dot-net-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
