In my app, ASP.NET MVC 4, EntityFramework and Syncfusion MVC controls i have problem with MVC Grid. I created OData source with Web API:
public class DriversController : ODataController
{
private ApplicationDbContext db = new ApplicationDbContext();
// GET: odata/Drivers
[EnableQuery]
public IQueryable<Driver> GetDrivers()
{
return db.Drivers;
}
...
}
And this works, tested with Postman. Get data and modify it in DB. But my grid:
@model dynamic
@(Html.EJ().Grid<object>("DriversGrid")
.Datasource("http://localhost:26168/odata/Drivers")
.Columns(col =>
{
col.Field("Id").HeaderText("ID").IsIdentity(true).IsPrimaryKey(true).AllowFiltering(false).Add();
col.Field("Name").HeaderText("Nazwa").Add();
col.Field("DriverId").HeaderText("ID pastylki").Add();
})
.AllowFiltering()
.FilterSettings(d => d.FilterType(FilterType.Menu))
.AllowSorting()
.ClientSideEvents(events =>
{
events.EndAdd("onEndAdd");
// events.Load("onLoad");
})
.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);
});
})
)
<script>
function onEndAdd(sender, args) {
var gridObj = $("#DriversGrid").ejGrid("instance");
gridObj.refreshContent();
};
</script>
only reads data from controller, actions on grid only calls public IQueryable<Driver> GetDrivers()
. No other actions on the controller are not called. Grid viually edits, deletes and insert data but not call odata source to store this.
What i'm doing wrong?
Should change data source from
.Datasource("http://localhost:26168/odata/Drivers")
to
.Datasource(d => d.URL("http://localhost:26168/odata/Drivers"))
This works fine.