排序生成的表在我的视图(visual studio .net)
本文关键字:visual studio net 视图 我的 排序 | 更新日期: 2023-09-27 18:14:20
<h2>Documenten</h2>
<table border="1"">
<tr>
<th">
title
</th>
<th>
description
</th>
<th>
Download
</th>
</tr>*
@foreach (var item in Model.Trajects.Components)
{
if (item.getType() == "document")
{
<tr>
<td>
@item.Title
</td>
<td>
@item.Description
</td>
<td><a href='@Url.Action("Download","Component", new {componentid=item.componentID,l=Request["trajectcode"],g = Model})'>
<img src='@Url.Content("../../Images/play.png")' alt="Home Page">
</a> </td>
</tr>
}
}
</table>
现在,当我初始化视图时,在标题上排序这个表的最好方法是什么?
我更喜欢在控制器中排序,但是您可以做以下操作:
@foreach (var item in Model.Trajects.Components.OrderBy(c => c.Title))
{
if (item.getType() == "document")
{
<tr>
<td>@item.Title</td>
<td>@item.Description</td>
<td>
<a href='@Url.Action("Download","Component", new { componentid = item.componentID, l = Request["trajectcode"], g = Model })'>
<img src='@Url.Content("../../Images/play.png")' alt="Home Page">
</a>
</td>
</tr>
}
}
参见foreach语句中的OrderBy