Books/Index.cshtml (Cont.)
@model IEnumerable<BookStore1.Models.Book>@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.DisplayNameFormodel => model.TitleModel 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 )@Html.DisplayFormodelItem => item.TitleTitle property of each individual item within that collection.
|
@model IEnumerable<BookStore1.Models.Book>
@{ ViewData["Title"] = "Index"; }
<h1>Index</h1>
<p><a asp-action="Create">Create New</a></p>
<table class="table">
<thead>
<tr>
<th>@Html.DisplayNameFor( model => model.Title )</th>
<th>@Html.DisplayNameFor( model => model.Genre )</th>
<th>@Html.DisplayNameFor( model => model.Price )</th>
<th>@Html.DisplayNameFor( model => model.PublishDate )</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach( var item in Model ) {
<tr>
<td>@Html.DisplayFor( modelItem => item.Title )</td>
<td>@Html.DisplayFor( modelItem => item.Genre )</td>
<td>@Html.DisplayFor( modelItem => item.Price )</td>
<td>@Html.DisplayFor( modelItem => item.PublishDate )</td>
<td>
<a asp-action="Edit" asp-route-id="@item.Id">Edit</a> |
<a asp-action="Details" asp-route-id="@item.Id">Details</a> |
<a asp-action="Delete" asp-route-id="@item.Id">Delete</a>
</td>
</tr>
}
</tbody>
</table>
|
|
“Do Transformers get a car or life insurance?” — Russell Howard |