[JsonSerializationException: Self referencing loop detected for property 'ApplicationInstance' with type 'ASP.global_asax'. Path 'childGrid.Context.ApplicationInstance.Context'.]
@code
Dim productGrid = Html.EJS().Grid("products")
With productGrid
.DataSource(Model.Products)
.Columns(Sub(col)
col.Field("Id").HeaderText("Product ID").TextAlign(TextAlign.Right).Add()
col.Field("Name").HeaderText("Naam").Add()
End Sub)
End With
Dim categoryGrid = Html.EJS().Grid("categories")
With categoryGrid
.DataSource(Model.ProductCategories)
.Columns(Sub(col)
col.Field("Id").HeaderText("ID").TextAlign(TextAlign.Right).Add()
col.Field("Product_Id").HeaderText("Product_Id").Add()
End Sub)
.QueryString("Product_Id")
.Height(200)
End With
End Code
<div class="gridCategories">@categoryGrid.Render()div>
@productGrid.ChildGrid(categoryGrid)
<div class="gridProducts">@productGrid.Render()div>
the data I have for products looks like:
{
"Id": 24,
"Name": "productX",
}
the data I get for categories looks like:
{
"Id": 2,
"ProductCategory_Id": 2,
"Product_Id": 24
},
If I comment out the second last line (productgrid.childgrid(categorygrid)) I get the two grids separately; if I uncomment that line it gives the above error
What am I doing wrong?
Hi,
I already have seen these links as well, so I have already added the following lines in my global.asax file, in the Application_Start() method:
Dim config = GlobalConfiguration.Configuration config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore
but still the errors is thrown. I think that somehow these settings are not used when calling the Grid.Render() function ?
Do you have any example where many-to-many data is shown in a grid with childgrids?
Thanks,
Koen
@Html.EJS().Grid("Grid").DataSource(ViewBag.ordersData).AllowPaging(True).Load("load").Columns(Sub(col)
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(True).Width("120").Add()
col.Field("CustomerID").HeaderText("Customer ID").Width("120").Add()
col.Field("EmployeeID").HeaderText("Employee ID").Width("120").Add()
End Sub).Render()
<script type="text/javascript">
var data = @Html.Raw(Json.Encode(ViewBag.employeesData)); // render the child Grid by using parent Grid load event
function load(args) {
this.childGrid = new ej.grids.Grid({
dataSource: data,
queryString: "EmployeeID",
load: function (args) {
this.query.queries.pop();
},
columns: [
{ field: 'FirstName', headerText: 'First Name', width: 120 },
{ field: 'LastName', headerText: 'Last Name', width: 120 }
]
});
}
</script> |
Private ReadOnly db As New NORTHWNDEntities
Public Property GridData As Object
Function Index() As ActionResult
ViewBag.ordersData = (From orders In db.Orders Select New With {orders.OrderID, orders.CustomerID, orders.EmployeeID}).ToList()
ViewBag.employeesData = (From employees In db.Employees Select New With {employees.EmployeeID, employees.FirstName, employees.LastName}).ToList()
Return View()
End Function |