[index.cshtml]
<ejs-grid id="Grid" toolbar="@(new List<string>() {"ExcelExport", "Add", "Update", "Cancel" })">
<e-data-manager url="/Home/UrlDatasource/" updateUrl="/Home/Update/" insertUrl="/Home/Insert/" removeUrl="/Home/Delete/" adaptor="UrlAdaptor" crossdomain="true"></e-data-manager>
<e-grid-editsettings allowEditing="true" allowAdding="true"></e-grid-editsettings>
...
</ejs-grid>
[HomeController.cs]
public class HomeController : Controller
{
private NORTHWNDContext _context;
public HomeController(NORTHWNDContext context)
{
_context = context;
}
public IActionResult UrlDataSource([FromBody]DataManagerRequest dm)
{
IEnumerable DataSource = _context.Orders.Take(100).ToList();
var count = _context.Orders.AsQueryable().Count();
DataOperations operation = new DataOperations();
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator);
}
if (dm.Skip != 0)
{
DataSource = operation.PerformSkip(DataSource, dm.Skip); //Paging
}
if (dm.Take != 0)
{
DataSource = operation.PerformTake(DataSource, dm.Take);
}
return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource);
}
public ActionResult Insert([FromBody]EditParams value)
{
var datas = _context;
datas.Orders.Add(value.value);
datas.SaveChanges();
return Json(value);
}
public ActionResult Update([FromBody]EditParams value)
{
var db = _context;
db.Entry(value.value).State = EntityState.Modified;
db.SaveChanges();
return Json(value);
}
public ActionResult Delete([FromBody]EditParams value)
{
var db = _context;
Orders order = db.Orders.Where(c => c.OrderID == Convert.ToInt32(value.key)).FirstOrDefault();
db.Orders.Remove(order);
db.SaveChanges();
return Json(order);
}
}
|
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
});
} |
public ActionResult Update([FromBody]CRUDModel<OrdersDetails> value)
{
var ord = value.value;
...
return Json(value.value);
}
public class CRUDModel<T> where T : class
{
public T value { get; set; }
}
|