@(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);
} |
GridFeatures.cshtml
@(Html.EJ().Grid<SyncfusionMvcApplication90.Models.Order>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
}))
public partial class Order
{
public int OrderID { get; set; }
[Required(ErrorMessage = "CustomerID is required")]
public string CustomerID { get; set; }
public Nullable<int> EmployeeID { get; set; }
public Nullable<System.DateTime> OrderDate { get; set; }
public Nullable<System.DateTime> RequiredDate { get; set; }
public Nullable<System.DateTime> ShippedDate { get; set; }
public Nullable<int> ShipVia { get; set; }
public Nullable<decimal> Freight { get; set; }
public string ShipName { get; set; }
public string ShipAddress { get; set; }
public string ShipCity { get; set; }
public string ShipRegion { get; set; }
public string ShipPostalCode { get; set; }
public string ShipCountry { get; set; }
public virtual Employee Employee { get; set; }
} |
<script src="Scripts/jquery.validate.min.js"></script>
<script src="Scripts/jquery.validate.unobtrusive.min.js"></script> |
GridFeatures.cshtml
@(Html.EJ().Grid<SyncfusionMvcApplication90.Models.Order>("FlatGrid")
.Datasource((IEnumerable<object>)ViewBag.datasource)
}))
public partial class Order
{
public int OrderID { get; set; }
[Required(ErrorMessage = "CustomerID is required")]
public string CustomerID { get; set; }
public Nullable<int> EmployeeID { get; set; }
public Nullable<System.DateTime> OrderDate { get; set; }
public Nullable<System.DateTime> RequiredDate { get; set; }
public Nullable<System.DateTime> ShippedDate { get; set; }
public Nullable<int> ShipVia { get; set; }
public Nullable<decimal> Freight { get; set; }
public string ShipName { get; set; }
public string ShipAddress { get; set; }
public string ShipCity { get; set; }
public string ShipRegion { get; set; }
public string ShipPostalCode { get; set; }
public string ShipCountry { get; set; }
public virtual Employee Employee { get; set; }
} |