0

In my ASP.NET MVC application, I have a partial view which renders a table.

My problem, in short, is that all the values of all the properties of each object in the WebGrid's data source are displayed inside the first column of the table, instead of a property value per column. I can see the per-property cell borders within each first column cell which hosts them.

The partial view's model is List<ReportTableEntry> where ReportTableEntry is:

public class ReportTableEntry
{
    public DateTime Time             { get; set; }
    public int      OpenedSessions   { get; set; }
    public int      ClosedSessions   { get; set; }
    public int      SnapshotSessions { get; set; }
    public int      TotalSessions    { get; set; }
}

The view which renders the partial view calls

@Html.Partial("Table", Model.TableEntries)

(here Model refers to the parent view's model rather than the partial view's model), where Model.TableEntries is a List, and within the partial view, the contents of Model seems to be valid when I inspect it.

I've tried every combination I can think of:

  • I used the parent view's model directly and created the WebGrid with source: Model.TableEntries.
  • I tried to use a non-typed model in the partial view.
  • I specified the grid's column names, and used default values.
  • I tried decorating ReportTableEntry's properties with ColumnAttribute.
  • I used grid.Html with and without styles, with and without the columns parameters
  • I toggled paging, sorting and added/removed the ajaxUpdateContainerId

Nevertheless, all the ReportTableEntry's property values are crammed inside the first table column.

One thing I noticed is that grid.Columns() returns an empty array.

For the sake of completeness, here's the simplest variation which produces these poor results:

@model List<ReportTableEntry>

<div id="reportDataDiv">
@{
    if (Model == null)
    {
        <p>No data to show</p>
    }
    else
    {
        var grid = new WebGrid(source:                Model, 
                               columnNames:           null, 
                               defaultSort:           "", 
                               rowsPerPage:           100, 
                               canPage:               true, 
                               canSort:               false, 
                               ajaxUpdateContainerId: "reportDataDiv");

        @grid.GetHtml()
    }
}
</div>

What am I missing here?

ury
  • 1,050
  • 11
  • 22

1 Answers1

0

How dumb... site.css, td element, float: left - and that's what happens.

ury
  • 1,050
  • 11
  • 22