I've created some grids that are bound to dynamic data. I used dapper to get the data i want from my database. for each grid i have set the model id and fields with the correct data types. my problem is, when creating/updating/deleting a record, the grid only sends an empty object to the appropriate controller. using reflection i can see this object has no fields, properties, or methods. Below I've included my grid configuration (Razor) and the update method. Can anyone see where i've gone wrong? i followed the example at this link to get as far as i currently am https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/grid/grid-bind-to-collection-dynamic/KendoMVCWrappers
Grid
<div class="container">
@{
int ctr = 0;
foreach(var table in Model)
{
<div style="margin-top:50px;">
@(Html.Kendo().Grid(table)
.Name($"Grid_{ctr.ToString()}")
.DataSource(ds=>ds
.Ajax()
.Model(m=> {
var dict = (IDictionary<string, object>)table.First();
var keyfield = dict.ElementAt(0).Key;
m.Id(keyfield);
foreach (var i in dict )
{
string key = i.Key;
var valuetype = i.Value.GetType();
m.Field(key,valuetype);
}
})
.Events(e=> { e.Sync("syncHandler");e.Change("syncHandler"); })
.Update(update=>update.Action("Update","MultiTable"))
.Create(create=>create.Action("Create","MultiTable"))
)
.BindTo(table)
.Pageable()
.Events(e => { e.Save("saveHandler");e.SaveChanges("saveChangesHandler"); })
.ToolBar(toolBar => { toolBar.Create();toolBar.Save(); })
.Editable(e=>e.Mode(GridEditMode.InCell)))
</div>
ctr++;
}
}
</div>
update method (dynamic id is always blank/empty)
[HttpPost]
public async Task<IActionResult> Update([DataSourceRequest]DataSourceRequest request, dynamic id)
{
//var m = id.model;
Type myType = id.GetType();
FieldInfo[] fields = myType.GetFields();
foreach (var field in fields)
{
var name = field.Name;
var tmp = field.GetValue(null);
if (tmp is int)
{
Console.Write("int");
}
else if (tmp is string)
{
Console.Write("string");
}
}
IList<PropertyInfo> props = new List<PropertyInfo>(myType.GetProperties());
foreach (PropertyInfo prop in props)
{
object propValue = prop.GetValue(id, null);
}
return View();
}