How to save data to the server

Hello
I'm using your grid in asp.net MVC core project, I have populated the grid with the code below in the razor files and this works fine,
But now I have to save the changed data to the database through the controller and do not know how to do this operation 
maybe I can see an example of how to do this?
Thanks in advance

Franco


.....
<div class="e-responsive">
    @{Html.EJ().Grid<List<DLCore.Models.Maintenance>>("FlatGrid")
                      .Datasource((IEnumerable<object>)ViewBag.Data)
                      .AllowPaging()
                      .AllowTextWrap()
                      .AllowSorting()
                      .AllowScrolling()
                      .ScrollSettings(col => { col.Width(1800).Height(600); })
                      .AllowSelection()
                      .SelectionType(SelectionType.Multiple)
                      .IsResponsive(true)
                      .EnableResponsiveRow(true)
                      .AllowFiltering()
                      .FilterSettings(filter => { filter.FilterType(FilterType.Excel); })
                  
                    .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.DialogTemplate).DialogEditorTemplateID("#template").ShowDeleteConfirmDialog(); })
                    .ToolbarSettings(toolbar =>
                    {
                        toolbar.ShowToolbar().ToolbarItems(items =>
                        {
                            items.AddTool(ToolBarItems.Add);
                            items.AddTool(ToolBarItems.Edit);
                            items.AddTool(ToolBarItems.Delete);
                            items.AddTool(ToolBarItems.Update);
                        });
                    })
                    .Columns(col =>
                    {
                        col.Field("Id").HeaderText("Id").IsPrimaryKey(true).Visible(false).Add();
                        col.Field("Cabin").HeaderText("Cabin").AllowResizing().Add();
                        col.Field("Line").HeaderText("Line").AllowResizing().Add();
                        col.Field("Turbine").HeaderText("Turbine").AllowResizing().Add();
                        col.Field("StatusCode").HeaderText("Status Code").AllowResizing().Add();
                        col.Field("dt_from").HeaderText("Start Date").Format("{0:dd/MM/yyyy HH:mm:ss}").AllowResizing().Add();
                        col.Field("dt_to").HeaderText("End Date").Format("{0:dd/MM/yyyy HH:mm:ss}").AllowResizing().Add();
                        col.Field("Timekey").HeaderText("Timekey").AllowResizing().Add();
                        col.Field("AlarmDescription").HeaderText("Alarm Description").AllowResizing().Add();
                        col.Field("Wind").HeaderText("Wind m/s during downtime").AllowResizing().Add();
                        col.Field("KindofActivity").HeaderText("Kind of Activity").AllowResizing().Add();
                        col.Field("MA_StatusCode").HeaderText("MA Status Code").AllowResizing().Add();
                        col.Field("ReasonDescription").HeaderText("Reason Description").AllowResizing().Add();
                        col.Field("timekey_changed").HeaderText("Timekey Changed").EditType(EditingType.Dropdown).AllowResizing().Add();
                        col.Field("Operation").HeaderText("Operation").AllowResizing().Add();
                    }).Render();
    }


2 Replies

FP franco perduca January 15, 2017 06:08 PM UTC

Hi
I have found our sample WebApplication8-1960312378 that show me exctaly what i need; but is possible to have sample that work in the same manner whit the grid edit-mode="Batch" ?
Thank you
Franco


MF Mohammed Farook J Syncfusion Team January 16, 2017 11:24 AM UTC

 Hi Franco, 
 
Thanks for contacting Syncfsuion Supports. 
 
Based on your requirement  we have created a sample and it can be downloaded from the following link. 
 
 
 
 
If you  are using ‘Batch’ editing with server side action for add/delete/update  , you need  to use ‘BatchURL’ for edit action. Please find the code example. 
 
 
[view] 
@{Html.EJ().Grid<WebApplication8.Controllers.HomeController.Orders>("HierarchyGrid")     
    .Datasource(ds => ds.Json(this.Model).BatchURL("/Home/BatchUpdate").Adaptor(AdaptorType.RemoteSaveAdaptor)) 
 
 
….. 
 
} 
 
[controller] 
 
//Batch URL   
 
        public ActionResult BatchUpdate([FromBody]CRUDModel<Orders> changed, [FromBody]CRUDModel<Orders> added, [FromBody]CRUDModel<Orders> deleted) 
        { 
           // do your database here 
            return View(); 
        } 
 
 
 
 
@{ 
    ViewData["Title"] = "Home Page"; 
} 
<h2>Index</h2> 
 
@using WebApplication8.Controllers 
@model List<WebApplication8.Controllers.HomeController.Orders> 
@{Html.EJ().Grid<WebApplication8.Controllers.HomeController.Orders>("HierarchyGrid") 
 
                                                      .Datasource(ds => ds.Json(this.Model).BatchURL("/Home/BatchUpdate").Adaptor(AdaptorType.RemoteSaveAdaptor)) 
                                                      .ShowColumnChooser() 
                                                      .AllowPaging() 
                                                            .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Batch); }) 
                              .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); 
                                  }); 
                              }) 
                                                                      .Columns(col => 
                                                                      { 
                                                                          col.Field("OrderID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(90).ValidationRules(v => v.AddRule("required", true).AddRule("number", true)).Add(); 
                                                                          col.Field("CustomerID").HeaderText("Customer ID").Width(90).Add(); 
                                                                          col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(90).Add(); 
                                                                          col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(80).EditType(EditingType.Numeric).Format("{0:C}").Add(); 
                                                                      }).Render(); 
} 
 
//  
 
        public ActionResult BatchUpdate([FromBody]CRUDModel<Orders> changed, [FromBody]CRUDModel<Orders> added, [FromBody]CRUDModel<Orders> deleted) 
        { 
           // do your database here 
            return View(); 
        } 
 
 
 
 
Regards, 
J.Mohammed Farook 


Loader.
Up arrow icon