| 1 | <h2>Full example</h2> |
| 2 | <pre><code>@* Source: https://docs.microsoft.com/en-us/aspnet/core/razor-pages/?view=aspnetcore-5.0&tabs=visual-studio#the-home-page *@ |
| 3 | |
| 4 | @page |
| 5 | @model RazorPagesContacts.Pages.Customers.IndexModel |
| 6 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers |
| 7 | |
| 8 | <h1>Contacts home page</h1> |
| 9 | <form method="post"> |
| 10 | <table class="table"> |
| 11 | <thead> |
| 12 | <tr> |
| 13 | <th>ID</th> |
| 14 | <th>Name</th> |
| 15 | <th></th> |
| 16 | </tr> |
| 17 | </thead> |
| 18 | <tbody> |
| 19 | @foreach (var contact in Model.Customer) |
| 20 | { |
| 21 | <tr> |
| 22 | <td> @contact.Id </td> |
| 23 | <td>@contact.Name</td> |
| 24 | <td> |
| 25 | <a asp-page="./Edit" asp-route-id="@contact.Id">Edit</a> | |
| 26 | <button type="submit" asp-page-handler="delete" |
| 27 | asp-route-id="@contact.Id">delete |
| 28 | </button> |
| 29 | </td> |
| 30 | </tr> |
| 31 | } |
| 32 | </tbody> |
| 33 | </table> |
| 34 | <a asp-page="Create">Create New</a> |
| 35 | </form> |
| 36 | </code></pre> |