@model IEnumerable<GroupResponse>
@* Generated from Custom MVC Template. *@
@* Model namespace using directive should be added to _ViewImports.cshtml. *@
@{
var containerDivClass = "container"; // "container-fluid" can be used for full width
}
@{
/*
ViewBag and ViewData are the same collection (dictionary).
They carry extra data other than the model from a controller action to its view, or between views.
The value assigned will be shown in Views\Shared\_Layout.cshtml view's title tag of the head tag.
*/
ViewData["Title"] = "Group List";
}
<div class="@containerDivClass">
<h1>@ViewData["Title"]</h1>
<hr />
</div>
@if (Model is not null)
{
<form asp-action="Index" autocomplete="off">
<div class="@containerDivClass">
<div class="row">
<div class="col-12 text-danger">
@*
TempData is used to carry extra data to the redirected controller action's view.
*@
@TempData["Message"]
</div>
</div>
<div class="row mb-3">
<div class="col-10 text-success">
@Model.Count() record(s) found.
</div>
<div class="col-2 text-end">
@if (User.IsInRole("Admin"))
{
<a asp-action="Create">Create</a>
}
</div>
</div>
<table class="table table-striped table-hover">
<thead class="table-secondary">
<tr>
<th>
@Html.DisplayNameFor(model => model.Title)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td class="text-end w-25">
@if (User.Identity.IsAuthenticated)
{
<a asp-action="Details" asp-route-id="@item.Id">Details</a>
if (User.IsInRole("Admin"))
{
@* Escaping special characters (here &) in Razor C# code: *@
@* Way 1: *@
@* <text> | </text> *@
@* Way 2: *@
@: |
<a asp-action="Edit" asp-route-id="@item.Id">Edit</a>
@: |
<a asp-action="Delete" asp-route-id="@item.Id">Delete</a>
}
}
</td>
</tr>
}
</tbody>
</table>
</div>
</form>
}