razor foreach in csharp

To use a foreach loop in Razor syntax within a C# code block, you can use the foreach keyword followed by parentheses containing the loop variable, the "in" keyword and the source data to iterate over. Inside the block of the loop, you can then access properties or values of the current item using the loop variable.

Here is an example of using foreach loop in Razor:

main.cs
@foreach(var item in Model)
{
    <div>@item.Name</div>
}
58 chars
5 lines

In this example, Model refers to the source data being passed to the view, and Name is a property of each item in the source data that is being displayed in a div tag for each iteration of the loop.

gistlibby LogSnag