Skip to content

Instantly share code, notes, and snippets.

@sunmeat
Created December 30, 2025 17:40
Show Gist options
  • Select an option

  • Save sunmeat/67db9b438fa785197bd18230d43cfc48 to your computer and use it in GitHub Desktop.

Select an option

Save sunmeat/67db9b438fa785197bd18230d43cfc48 to your computer and use it in GitHub Desktop.
правки показу списку гравців у вью для сортування по стовпчиках
@model IEnumerable<Soccer.Models.Player>
@{
ViewData["Title"] = "Гравці";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h1>Список гравців</h1>
<p>
<a asp-action="Create" class="btn btn-primary">Додати нового гравця</a>
</p>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>
<a asp-action="Index" asp-route-sortOrder="@ViewData["NameSort"]">
@Html.DisplayNameFor(model => model.Name)
@if (ViewData["CurrentSort"]?.ToString()?.StartsWith("name") == true)
{
<span>@(ViewData["CurrentSort"]?.ToString() == "name_desc" ? " ▼" : " ▲")</span>
}
</a>
</th>
<th>
<a asp-action="Index" asp-route-sortOrder="@ViewData["AgeSort"]">
@Html.DisplayNameFor(model => model.Age)
@if (ViewData["CurrentSort"]?.ToString()?.StartsWith("age") == true)
{
<span>@(ViewData["CurrentSort"]?.ToString() == "age_desc" ? " ▼" : " ▲")</span>
}
</a>
</th>
<th>
<a asp-action="Index" asp-route-sortOrder="@ViewData["PositionSort"]">
@Html.DisplayNameFor(model => model.Position)
@if (ViewData["CurrentSort"]?.ToString()?.StartsWith("position") == true)
{
<span>@(ViewData["CurrentSort"]?.ToString() == "position_desc" ? " ▼" : " ▲")</span>
}
</a>
</th>
<th>
<a asp-action="Index" asp-route-sortOrder="@ViewData["TeamSort"]">
Команда
@if (ViewData["CurrentSort"]?.ToString()?.StartsWith("team") == true)
{
<span>@(ViewData["CurrentSort"]?.ToString() == "team_desc" ? " ▼" : " ▲")</span>
}
</a>
</th>
<th>Дії</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Age)
</td>
<td>
@Html.DisplayFor(modelItem => item.Position)
</td>
<td>
@Html.DisplayFor(modelItem => item.Team.Name)
</td>
<td>
<a asp-action="Edit" asp-route-id="@item.Id">Редагувати</a> |
<a asp-action="Details" asp-route-id="@item.Id">Деталі</a> |
<a asp-action="Delete" asp-route-id="@item.Id">Видалити</a>
</td>
</tr>
}
</tbody>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment