Ta, już to przeglądałem,
ale ja dalej nie kumam jak mam tego użyć...
Proszę o pomoc
o to mój widok, chce posortować po Dacie:
@model IEnumerable<MvcMusicStore.SQL.Albums>
@helper Truncate(string input, int length)
{
if (input.Length <= length)
{
@input
}
else
{
@input.Substring(0, length)<text>...</text>
}
}
<link href="~/Content/css/select2.css" rel="stylesheet" />
<link href="~/Content/css/select2.min.css" rel="stylesheet" />
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
Image
</th>
<th>
Artists
</th>
<th>
Genres
</th>
<th>
@Html.DisplayNameFor(model => model.Title)
</th>
<th>
@Html.DisplayNameFor(model => model.Price)
</th>
<th>Country</th>
<th>
Actions
</th>
<th>
CreatedAt
</th>
<th>
</th>
</tr>
<tbody style="text-align: left; ">
@foreach (var item in Model)
{
<tr>
<td>
<div>
@if (item.AlbumImage != null)
{ <img src="data:image/png;base64, @item.AlbumImage" alt="Red dot" style="max-width:150px; max-height:150px;" /> }
</div>
</td>
<td>
@Html.GetArtistId(item.ArtistId)
</td>
<td>
@Html.GetGenreId(item.GenreId)
</td>
<td>
@Truncate(item.Title, 25)
</td>
<td>
@Html.DisplayFor(modelItem => item.Price)
</td>
<td>
@Html.GetCountry(item.CountryId)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.AlbumId }) |
@Html.ActionLink("Details", "Details", new { id = item.AlbumId }) |
@Html.ActionLink("Delete", "Delete", new { id = item.AlbumId })
</td>
<td>
@if (item.CreatedAt != null)
{
@item.CreatedAt.OrderByDescending(x => x.CreatedAt).ToList();
}
</td>
</tr>
}
</tbody>
</table>
Błąd nastaje dokładnie przy wywołaniu: @item.CreatedAt.OrderByDescending(x => x.CreatedAt).ToList();
Rozumiem, że CreatedAt nie ma takiej funkcji, ale nie mam innego pomysłu na rozwiązanie sprawy
Severity Code Description Project File Line Suppression State
Error CS1061 'DateTime?' does not contain a definition for 'OrderByDescending' and no extension method 'OrderByDescending' accepting a first argument of type 'DateTime?' could be found (are you missing a using directive or an assembly reference?) 5_Views_StoreManager_Index.cshtml C:\Users\Mateusz\Documents\Visual Studio 2017\Projects\MvcMusicStore\MvcMusicStore\Views\StoreManager\Index.cshtml 99 Active