Hi,
I've created a new project from the Syncfusion template using the Syncfusion VS extensions. I've created my EF Model and DataContext and used the instructions
here to create an editable grid.
Model and DataContext:
public class Season
{
public int Id { get; set; }
public string SeasonName { get; set; }
}
// From DbContext
public DbSet<Season> Seasons { get; set; }
Here is my controller:
public class SeasonsController : Controller
{
private ApplicationDbContext db = new ApplicationDbContext();
public ActionResult Index()
{
IEnumerable<Season> seasons = db.Seasons;
return View(seasons);
}
public ActionResult Update(Season value)
{
Season season = db.Seasons.Find(value.Id);
season.SeasonName = value.SeasonName;
db.SaveChanges();
var data = db.Seasons;
return Json(data, JsonRequestBehavior.AllowGet);
}
public ActionResult Insert(Season value)
{
db.Seasons.Add(value);
var data = db.Seasons;
return Json(data, JsonRequestBehavior.AllowGet);
}
public ActionResult Delete(int key)
{
Season season = db.Seasons.Find(key);
db.Seasons.Remove(season);
db.SaveChanges();
var data = db.Seasons;
return Json(data, JsonRequestBehavior.AllowGet);
}
public ActionResult Paul()
{
IEnumerable<Season> seasons = db.Seasons;
return View(seasons);
}
}
And here is my index page:
@model IEnumerable<SyncfusionMvcApplication4.Models.Season>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@(Html.EJ().Grid<SyncfusionMvcApplication4.Models.Season>("Editing")
.Datasource(ds => ds.Json((IEnumerable<object>)Model).UpdateURL("Seasons/Update").InsertURL("Seasons/Insert").RemoveURL("Seasons/Delete").Adaptor(AdaptorType.RemoteSaveAdaptor))
.AllowSorting()
.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);
});
})
.AllowPaging()
.Columns(col =>
{
col.Field("Id").HeaderText("Id").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(90).ValidationRules(v => v.AddRule("required", true).AddRule("number", true)).Add();
col.Field("SeasonName").HeaderText("Season Name").TextAlign(TextAlign.Right).Width(90).ValidationRules(v => v.AddRule("required", true)).Add();
})
)
The page loads but there is no grid. The firebug console picks up this error:
uncaught exception: DataManger : a dataSource is required to create Manager
u@http://localhost:49339/Scripts/ej/ej.web.all.min.js:10:70811
t.DataManager@http://localhost:49339/Scripts/ej/ej.web.all.min.js:10:20276
t.DataManager@http://localhost:49339/Scripts/ej/ej.web.all.min.js:10:20248
@http://localhost:49339/Seasons/Index:62:252
x.Callbacks/c@http://localhost:49339/Scripts/jquery-1.10.2.min.js:21:26031
x.Callbacks/p.fireWith@http://localhost:49339/Scripts/jquery-1.10.2.min.js:21:26840
.ready@http://localhost:49339/Scripts/jquery-1.10.2.min.js:21:3303
q@http://localhost:49339/Scripts/jquery-1.10.2.min.js:21:715
I can confirm that there is data in the model from the controller.
Do you see where I am going wrong? I just cannot seem to make it work!
Thanks you,
Paul.