How to display data in matrix form - Asp.Net MVC

I have one table structure Like

1) Identifier 2) Date 3) Assessment

Filtered by date, I can show the number of rows (Display: Score field).

and on one page I am showing records of three dates (3 consecutive dates stored in tables).

The format should look like ...

Date1 Date2 Date3

evaluation of the result

evaluation of the result

evaluation of the result

.........

should i create my own model using existing class classes?

I don't know what will be in your mind, but can user control help me in this situation?

Please help me...

Public request update

using

<% foreach (var item in Model) { %>
<% } %>

      

Each record can be easily displayed in an index view.

How about the structure above?

If you don't receive ...

records:

1 21/2/2009 29

2 21/2/2009 50

3 21/2/2009 54

2 21/2/2009 77

2 23/2/2009 55

2 23/2/2009 44

2 23/2/2009 66

2 24/2/2009 53

Display

21/2/2009 | 23/2/2009 | 24/2/2009

29 | 55 | 53

50 | 44 |

54 | 66 |

77 |

0


a source to share


1 answer


I posted this out of my mind - so there may be typos / errors.

First you need a custom model:

public class ScoreColumnViewModel {
    public DateTime Date;
    public List<int> Score;
}

      

In your controller, create a ScoreColumnViewModel list (assume Linq-To-Sql):

var dates = /* dates to select */

var scoreColumns = dates.Select(date =>
    new ScoreColumnViewModel {
        Date = date;
        Score = DB.Scores.Where(x => x.Date == date).
                    Select(x => x.Score).ToList();
    }
).ToList();

      



In your view:

<% foreach(var column in Model) { %>
    <table>
        <tr><th><%= column.Date %></th></tr>
        <% foreach(var score in column.Scores) { %>
            <tr><td>score</td></tr>
        <% } %>
    </table>
<% } %>

      

In your css:

table {
    float: left;
}

      

My solution is not perfect, but it might be a starting point for you.

+1


a source







All Articles