We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Grid BatchUpdate using ASP.Net Core Razor pages

Hello,
I have been successful in showing the grid data using ASP.Net Core 2.2 Razor pages but not the Grid batchupdate. I am also unable to find the appropriate documentation. I have also checked the demos. Here's my source code: Can you please help? 

<ejs-grid id="GridNewKeywords" dataSource="@Model.Input.KeywordsForUser" toolbar="@(new List<string>() { "Add", "Delete","Update","Cancel" })" allowPaging="true">
                                            <e-data-manager url="/Home/BatchData" batchUrl="/Home/BatchUpdate" adaptor="UrlAdaptor"/>
                                            <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Batch" />
                                            <e-grid-pagesettings pageCount="5" pageSize="5" />
                                            <e-grid-columns>
                                                <e-grid-column field="KeywordId" headerText="Id" isPrimaryKey="true" width="0" />
                                                <e-grid-column field="Value" headerText="Keyword"
                                                               validationRules="@(new { required=true})" />
                                            </e-grid-columns>
                                        </ejs-grid>


public class InputModel
    {
      public List<Keyword> KeywordsForUser { get; set; }
    }
public async Task OnGetAsync()
    {
      var predefinedKeywords = await ScrubberDbContext.PredefinedKeywords.ToListAsync();

      this.Input = new InputModel
      {
        KeywordsForUser = await keywordsForUser.ToListAsync()
      };
    }



1 Reply

HJ Hariharan J V Syncfusion Team May 14, 2019 01:16 AM

Hi ajit, 
  
Thanks for contacting Syncfusion support. 
  
We have validated your requirement. To perform the batch update in URL adaptor you need to handle the data in controller side Please find the below code snippet and sample for more information. 
  
       Index.cshtml 
  
<ejs-grid id="Grid" allowPaging="true" load="onLoad" toolbar="@( new List<object>() {"Add","Edit","Delete","Update","Cancel"})"> 
    <e-grid-editsettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Batch"></e-grid-editsettings> 
    <e-data-manager url="/Index?handler=DataSource" batchUrl="/Index?handler=BatchUpdate" adaptor="UrlAdaptor"></e-data-manager> 
. . . 
    </e-grid-columns> 
</ejs-grid> 
  
  
Index.cshtml.cs 
  
public JsonResult OnPostBatchUpdate([FromBody]CRUDModel batchmodel
        { 
            if (batchmodel.Changed.Count != 0) 
            { 
                for (var i = 0; i < batchmodel.Changed.Count(); i++) 
                { 
                    var ord = batchmodel.Changed[i]; 
                    Orders val = order.Where(or => or.OrderID == ord.OrderID).FirstOrDefault(); 
                    val.OrderID = ord.OrderID; 
                    val.EmployeeID = ord.EmployeeID; 
                    val.CustomerID = ord.CustomerID; 
                    val.ShipCity = ord.ShipCity; 
                } 
            } 
  
            if (batchmodel.Deleted.Count != 0) 
            { 
                for (var i = 0; i < batchmodel.Deleted.Count(); i++) 
                { 
                    order.Remove(order.Where(or => or.OrderID == batchmodel.Deleted[i].OrderID).FirstOrDefault()); 
                } 
            } 
  
            if (batchmodel.Added.Count != 0) 
            { 
                for (var i = 0; i < batchmodel.Added.Count(); i++) 
                { 
                    order.Insert(0, batchmodel.Added[i]); 
                } 
            } 
            var data = order.ToList(); 
            return new JsonResult(data); 
        } 
  
  
Please get back to us if you need further assistance. 
  
  
Regards, 
Hariharan 


Loader.
Live Chat Icon For mobile
Up arrow icon