Skip to main content

Use of MVC ViewBag List Items in Razor for-each loop

MVC Razor for-each loop with ViewBag List Items and the code-sample for the razor for-each loop with respect to the ViewBag.

@foreach (var employee in ((List<Employee>)ViewBag.Employees))
{
    <span>@employee.EmployeeCode</span>
    <span>@employee.Name</span>
}


Thank you!