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
1: @model IEnumerable<BookStore.Models.Category>
Now write foreach loop
1: <body>
2: @if (Model != null)
3: {
4: foreach (var item in Model)
5: {
6: <ul id="menu">
7:
8: <li>
9: @Html.DisplayFor(modelItem => item.BookName)
10: </li>
11: <li>
12: @Html.DisplayFor(modelItem => item.Title)
13: <br />
14: </li>
15: <li>
16: @Html.DisplayFor(modelItem => item.BookId)
17: </li>
18: </ul>
19: }
20: }
21: </body>
Thanks
To know more about MVC kindly go through with the links given below:
- Smart Working With Custom Value Providers in ASP.Net MVC
- Invoke Action With Model Binders in MVC
- Extension Helpers Method in MVC
- Custom Button With TagBuilder Using MVC Razor Engine
- Precompiled Razor View Using RazorGenerator MVC and PreCompiledViewEngine in MVC 4
- RETURN MULTIPLE MODELS IN SINGLE VIEW IN MVC3
- CALL CONTROLLER ACTION METHOD FROM JQUERY USING AJAX
- EXECUTION ORDER OF FILTERS IN MVC 4 WITH PRACTICES: IMPORTANT FAQ
- MEANING OF SCAFFOLDING IN MVC
- REMOVE AMBIGUTY OF CONTROLLER NAMES IN MVC APPLICATION
- CUSTOM BUTTON WITH TAGBUILDER TECHNIQUE USING MVC RAZOR ENGINE
- CONVERSION HELPERS IN MVC RAZOR: VALIDATING POSTED DATA
This comment has been removed by a blog administrator.
ReplyDelete