Loop through Model items in ASP.NET MVC
To loop through Model items in ASP.NET MVC view, use foreach loop in the Controller,which returns Collection of items.
Add the given below line to bind your model with .cshtml page.
- 1: @model IEnumerable<BookStore.Models.Category>
Now write foreach loop at view level page(.cshtml).
- @if (Model != null)
- {
- foreach (var item in Model)
- {
- <ul id="menu">
- <li>
- @Html.DisplayFor(modelItem => item.Address)
- </li>
- <li>
- @Html.DisplayFor(modelItem => item.City)
- <br />
- </li>
- <li>
- @Html.DisplayFor(modelItem => item.Id)
- </li>
- </ul>
- }
- }

Rahul PatelPosted Mar 14, 2018, 3:20 PM
Im getting this please can you help me
Rahul PatelPosted Mar 14, 2018, 3:20 PM
List<HomeShortContent> CommunityList = new List<HomeShortContent>(); var TempPremiumList = from adm in context.AddMasters.Where(a => a.IsDeleted == false && a.AddTypeID == 3 && a.Status.Equals("Approved")) .OrderByDescending(b => b.AddTitle).Select(c => c.PostedDate).Take(3).ToList();
shashank tripathiPosted Feb 20, 2018, 4:46 AM
How to use multiple class model in collection for view in foreach loop sir..please suggest me