c# - Sorting a generated table in my view (visual studio .net) -
<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>
now, whats best way sort table on title, when initialize view?
i prefer sort in controller, can following:
@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> } }
see orderby
in foreach statment.
Comments
Post a Comment