Scenario:
I activates the javascript ajax request by clicking a button client side,
then the request will retreive data from server side and pass data to view by "ViewBag",
I've already checked that the data were passed into view successfully,
but the grid didn't show up,
However I haven't got any error message while debugging in Visual studio or Browser Dev tool.
To be mentioned, my ViewBag passed in a View Model,
which there are "IEnumearable<SubModel>" models in it.
So what actually would bind with grid is the data in sub models.
What I've tried:
1. Testing Grid without giving data => the grid showed up without data
2. Grid with data from ViewBag => ends up with entire grid not showing
(With the first test, I'm guessing it is the data binding error makes the entire grid not showing)
Code:
MyViewModel.cs
public class MyViewModel
{
//What really binds to the grid,Ex: Model1
public IEnumerable<MyModel1> Model1 { get; set; }
public IEnumerable<MyModel2> Model2 { get; set; }
public IEnumerable<MyModel3> Model3 { get; set; }
}
MyCshtml.cshtml
@model IEnumerable<MyViewModel>
@{
//ViewModel with sub Models in it passed into view by ViewBag
var Datas = (MyViewModel)ViewBag.MyViewModel;
}
<head>
<script src="~/QueryData/js/MyData.js"></script>
</head>
<body>
@(Html.Kendo().Grid<MyModel1>(Datas.Model1)
.Name("my-grid")
.Columns(columns =>
{
columns.Bound(c => c.Name).Title("Name").Width(30);
columns.Bound(c => c.ReadData).Title("Data").Width(30);
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.HtmlAttributes(new { style = "height:500px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(5)
.ServerOperation(false)
)
)
</body>
Reference: ASP.NET Core Local Data Binding
Looking into MyCshtml.cshtml again,
I've used the @model and referenced "IEnumerable<MyViewModel>",
However, what really binds with the Grid is the sub model in MyViewModel.
Maybe its the reason why the Grid was not showing?
If it is, is there any alternative work arrounds?
My final goal it to pass sub model into a partial view with grid in it, wich renders on MyCshtml.cshtml