How to loop through Model items in ASP.NET MVC

Sheonarayan
Posted by Sheonarayan under ASP.NET MVC category on | Points: 40 | Views : 9134
To loop through Model items in ASP.NET MVC view, use foreach loop

Ensure that your Controller is returning Collection of items and your model directive look like this

@model IEnumerable<MyFunda.Models.VideoModel>

Now write foreach loop

@foreach (var item in Model) {

<p>@Html.DisplayFor(modelItem => item.UserName)</p>

}


Thanks

Comments or Responses

Login to post response