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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Grid BatchUpdate using ASP.Net Core Razor pages

Thread ID:

Created:

Updated:

Platform:

Replies:

144526 May 9,2019 12:20 PM UTC May 14,2019 09:16 AM UTC ASP.NET Core - EJ 2 1
loading
Tags: DataGrid
ajit goel
Asked On May 9, 2019 12:20 PM UTC

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()
      };
    }



Hariharan J V [Syncfusion]
Replied On May 14, 2019 09:16 AM UTC

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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon