Generated Views: Books/Index.cshtml (Cont.)

@model IEnumerable<BookStore1.Models.Book>
The @model IEnumerableIEnumerable<BookStore1.Models.Book> directive is used in Razor views to specify that the view expects a collection of objects of type BookStore1.Models.Book. This is commonly used when you want to display a list of items, such as in a table or a list format.

@Html.DisplayNameFor
It is a helper method used to retrieve and display the display name of a model property. It is particularly useful in scenarios like creating table headers or form labels, where you want to show a user-friendly name for a property.

model => model.Title
If you have a Model object passed to a view, you can access its properties, such as Title, directly in the Razor view by using Lambda expressions. The => operator is used to separate the lambda’s parameter list from its body.

foreach( var item in Model )
It is used to iterate over a collection of objects that is passed to the view as part of its model.

@Html.DisplayFor
It is a helper method used to display the value of a model property in a view. It automatically applies formatting and uses display templates if defined, making it a robust and reusable way to render data.

modelItem => item.Title
It is a common way to specify the Title property of each individual item within that collection.
C:\ASP.NET-workspace\BookStore1\Views\Books\Index.cshtml
01@model IEnumerable<BookStore1.Models.Book>
02 
03@{ ViewData["Title"] = "Index"; }
04<h1>Index</h1>
05<p><a asp-action="Create">Create New</a></p>
06 
07<table class="table">
08  <thead>
09    <tr>
10      <th>@Html.DisplayNameFor( model => model.Title )</th>
11      <th>@Html.DisplayNameFor( model => model.Genre )</th>
12      <th>@Html.DisplayNameFor( model => model.Price )</th>
13      <th>@Html.DisplayNameFor( model => model.PublishDate )</th>
14      <th></th>
15    </tr>
16  </thead>
17   
18  <tbody>
19    @foreach( var item in Model ) {
20      <tr>
21        <td>@Html.DisplayFor( modelItem => item.Title )</td>
22        <td>@Html.DisplayFor( modelItem => item.Genre )</td>
23        <td>@Html.DisplayFor( modelItem => item.Price )</td>
24        <td>@Html.DisplayFor( modelItem => item.PublishDate )</td>
25        <td>
26          <a asp-action="Edit" asp-route-id="@item.Id">Edit</a> |
27          <a asp-action="Details" asp-route-id="@item.Id">Details</a> |
28          <a asp-action="Delete" asp-route-id="@item.Id">Delete</a>
29        </td>
30      </tr>
31    }
32  </tbody>
33</table>





      “Do Transformers get a car or life insurance?”    
      — Russell Howard