http://mvc.syncfusion.com/demos/web/grid/externalformediting public ActionResult ExternalUpdate(EditableOrder value) { OrderRepository.Update(value); var data = OrderRepository.GetAllRecords(); return Json(value, JsonRequestBehavior.AllowGet); } public ActionResult ExternalInsert(EditableOrder value) { OrderRepository.Add(value); var data = OrderRepository.GetAllRecords(); return Json(value, JsonRequestBehavior.AllowGet); } public ActionResult ExternalDelete(int key) { OrderRepository.Delete(key); var data = OrderRepository.GetAllRecords(); return Json(data, JsonRequestBehavior.AllowGet); }
But Confusing information here vs... https://help.syncfusion.com/aspnetmvc/grid/data-adaptors?cs-save-lang=1&cs-lang=csharp#remotesave-adaptornamespace EJGrid.Controllers { public class HomeController : Controller { public ActionResult Index() { var data = OrderRepository.GetAllRecords(); ViewBag.dataSource = data; return View(); } public ActionResult Update(EditableOrder value) { OrderRepository.Update(value); var data = OrderRepository.GetAllRecords(); return Json(data, JsonRequestBehavior.AllowGet); } public ActionResult Insert(EditableOrder value) { OrderRepository.Add(value); var data = OrderRepository.GetAllRecords(); return Json(data, JsonRequestBehavior.AllowGet); }
thanks
If (SfGridCollectoinWithFK == true) // on the link shows the difference after I did some troubleshooting, but the sample case is not show in the help grid. http://stackoverflow.com/a/17726414/6085193 I am guessing this is when there are Foreign Key attached to the grid.Basically, the gird needs an easy way (sample) to handle deletes regardless of the bindings.
{ removeURL }
else
if (SfGridCollectoinNo == true)
{ deleteURL } // but there is not delte URL on the adaptor
//Perform update
public void PerformUpdate(OrderTable value)
{
db.Entry(value).State = EntityState.Modified;
db.SaveChanges();
} |
//Perform update
public void PerformUpdate(OrderTable value)
{
db.Entry(value).State = EntityState.Modified;
db.SaveChanges();
} |
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource(ds => ds.URL("/Grid/DataSource").UpdateURL("/Grid/Update").InsertURL("/Grid/Insert").Adaptor(AdaptorType.UrlAdaptor))
}).ClientSideEvents(eve => { eve.ActionFailure("Failure"); }))
<script type="text/javascript">
function Failure(args) {
var popupObj = $("#FlatGrid").data("ejWaitingPopup");
popupObj.hide();
this.cancelEdit();
var str = "";
str = args.error.statusText;
alert(str);
}
</script>
GridController.cs
public ActionResult DataSource(DataManager dm)
{
DataOperations ds = new DataOperations();
var data = ds.Execute(OrderRepository.GetAllRecords().ToList(), dm);
return Json(new { result = data, count = db.Orders.ToList().Count }, JsonRequestBehavior.AllowGet);
}
public ActionResult Update(EditableOrder value)
{
if (!ModelState.IsValid)
{
var message = string.Join(" | ", ModelState.Values
.SelectMany(v => v.Errors)
.Select(e => e.ErrorMessage));
return new HttpStatusCodeResult(HttpStatusCode.BadRequest, message);
}
EditableOrder old = OrderRepository.GetAllRecords().Where(o => o.OrderID == value.OrderID).SingleOrDefault();
return Json(OrderRepository.GetAllRecords(), JsonRequestBehavior.AllowGet);
} |