I need to do this using reflection:
@Html.Grid((IEnumerable<MyType>)list).Columns(columns =>
{
columns.Add(foo => foo.Title)
.Titled("Custom column title")
.SetWidth(110);
columns.Add(foo => foo.Description)
.Sortable(true);
}).WithPaging(20)
Now I have var g
which is object created after call @Html.Grid((IEnumerable<Type>)Model)
using reflection. This is done by reflection because list contains object of class created at runtime and I need to call Grid(list) with defined type(which didn't exist at compile time):
var method = typeof(GridMvc.Html.GridExtensions).GetMethods()
.Where(mi => mi.Name == "Grid")
.ElementAt(0)
.MakeGenericMethod(new Type[] { t });
var g = method.Invoke(null, new object[] { Html, list });
So I need do something like:
g.Columns(columns =>
{
columns.Add(foo => foo.Title)
.Titled("Custom column title")
.SetWidth(110);
columns.Add(foo => foo.Description)
.Sortable(true);
}).WithPaging(20)
using reflection.
var g
is type of HtmlGrid:
https://github.com/leniel/Grid.Mvc/blob/master/GridMvc/Html/HtmlGrid.cs
Can someone provide example code to do this?
To be on the safe side I am adding Grid.Mvc github link: https://github.com/leniel/Grid.Mvc/blob/master/GridMvc/ because I don't know the way to solve it