Formatting ASP.NET MVC Data

Let's say I have a database table as shown below:

FileID | FileName | FileSize | Group
-------------------------------------
1        test.txt   100        Group1
2        test2.txt  100        Group1
3        test3.txt  100        Group2

What would be the best way to display this data with a MVC style representation:

Group 1

Table containing Group1 files


Group 2

Table containing Group1 files


What I get when I group the results by Group through the linq to sql query, how can I efficiently display file lists in sections.

Thanks for any input.

+3
source share
1 answer

Here is an example ... I assume a strongly typed model that contains a list of groups with corresponding files ...

MODEL

public class Groups
{
    public List<Files> GroupFiles { get; set; }
    public String Name{ get; set; }
}

public class File
{
    public int FileId { get; set; }
    public String FileName { get; set; }
    public String FileSize { get; set; }
}

VIEW

<%
foreach(var group in myModel.FileGroups)
{
%>
      <h2><%= group.Name %></h2>
      <table>
<%   
    foreach(var file in group.Files)
    { %>

         <tr>
             <td><%= file.FileID %></td>
             <td><%= file.FileName %></td>
             <td><%= file.FileSize %></td>
         </tr>

    <%
    } %>
</table>
<%
}
%>
+5
source

Source: https://habr.com/ru/post/1710872/


All Articles