Displaying generic data?

Apr 28, 2015 at 12:53 PM
I might be going at this from a totally wrong angle, but I'm pretty new at MVC, so have some patiance will you...?

I need to display the contents of several rows of data. I don't know the number of rows, nor the number of columns. Currently, I have a view model looking something like this:

public string[] Columns { get; set; }
public List<string[]> Rows { get; set; }

Columns could look like this (but not necessarily have to):
"col 1", "col 2", "col 3"

and Rows would then be:
"row 1-1", "row 1-2", "row 1-3",
"row 2-1", "row 2-2", "row 2-3"
etc

I would like the final grid to look like

col 1 | col 2 | col 3

row 1-1 | row 1-2 | row 1-3
row 2-1 | row 2-2 | row 2-3


but I can't figure out how to display this using Html.Grid() since I don't have properly named properties for the column names. Suggestions?
Sep 18, 2015 at 5:04 PM
I too have a similar issue and it appears GridMVC will only work on defined objects I.E. Your strongly typed model classes, classes that can be reflected using GetType or typeof.
It seems there is not an implementation for "dynamic" objects. I.E. ExpandoObject.
Dec 17, 2015 at 8:00 PM
Edited Dec 17, 2015 at 8:03 PM
I, also, am in need of something like this and am tired of using client-side "grids" to do the work.

Are you sure that it can't be done as his base object could be setup like this:
public class myData {
    public List<MyColumn> Cols {get; set;}
    public List<MyRow> Rows {get; set;}
}

public class MyColumn {
    public string ColumnName {get; set;}
}

public class MyRow {
    public string[] RowData {get; set;}
}
We currently send the data in JSON format and serialize into our Model and dynamically build our columns, then populate the grid afterwards.

Couldn't the .columns be added in a loop in the razor code?