@(Html.EJ().Grid<object>("ForeignKey")
.Datasource((IEnumerable<object>)ViewBag.empDataSource)
.AllowPaging()
.AllowGrouping()
.AllowFiltering()
.FilterSettings(filter => { filter.FilterType(FilterType.Menu); })
.EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); })
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.Update);
items.AddTool(ToolBarItems.Cancel);
});
})
.Columns(col =>
{
----------------
col.Field("EmployeeID").HeaderText("Employee Name").ForeignKeyField("EmployeeID")
.ForeignKeyValue("FirstName").DataSource((IEnumerable<object>)ViewBag.foncDataSource)
.TextAlign(TextAlign.Left).Width(90).Add();
----------------------
}
)
) |
Queries |
Response | |
“Circular Reference Error”
|
The circular reference error will reproduced when we have same table the object can be serialized.
To avoid the circular reference error, use the below code example
We can also use select method to get the selected data from the table and data has been binded to the grid. For the following error please refer this link
Link : http://blog.davebouwman.com/2011/12/08/handling-circular-references-asp-net-mvc-json-serialization/
| |
“the column of the foreign key is not bound to the grid and when I open the edit form”
|
In last update you have mentioned the column of the foreign key is not bound to the Grid.
Foreign key is a field in a table which uniquely identifies a row of another table. To uniquely identify the relationship between both the tables, the Foreign key simply requires that the value of that field must exist first in a different table (the parent table).
In this, we have bound the datasource for the foreign key column. The datasource which we bound to the foreign key requires that the value in that RegionID field must exist first in the parent table. If the field does not exist in the parent table, it will show Null value in the column.
Please share the screenshot or video demo of an issue, it will help us to provide the prompt solution.
|
@(Html.EJ().Grid<object>("ForeignKey")
.Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.empDataSource).UpdateURL("NormalUpdate").InsertURL("NormalInsert").RemoveURL("NormalDelete").Adaptor(AdaptorType.RemoteSaveAdaptor))
..
.Columns(col =>
{
col.Field("TerritoryID").HeaderText("Territory ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();
col.Field("Regio.RegionID").HeaderText("Employee Name").ForeignKeyField("RegionID")
.ForeignKeyValue("RegionDescription").DataSource((IEnumerable<object>)ViewBag.foncDataSource)
.TextAlign(TextAlign.Left).Width(90).Add();
}
)
)
HomeController.cs
public ActionResult NormalUpdate(Territory2 value)
{
//do your operations here
return Json(value, JsonRequestBehavior.AllowGet);
}
public ActionResult NormalInsert(Territory2 value)
{
//do your operations here
return Json(value, JsonRequestBehavior.AllowGet);
}
public ActionResult NormalDelete(int key)
{
//do your operations here
return Json(data, JsonRequestBehavior.AllowGet);
}
|