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

How to redirect after batch update in server correctly

Hi,

I have a grid control in batch mode settings:

  <ejs-grid id="Grid" toolbar="@(new List<string>() { "Update", "Cancel" })" 
            load="load" befo>
            <e-data-manager url="/ProjectTasks/UrlDataSource/?id=@Model.ProjectTaskID"
                            batchUrl="/ProjectTasks/BatchUpdate"
                            adaptor="UrlAdaptor"></e-data-manager>
            <e-grid-editSettings allowEditing="true"
                                 mode="Batch"
                                 showConfirmDialog="true" showDeleteConfirmDialog="true">

I get the data in controller and save correctly to database, returning a Json result.
I need in a correct saved data controller operation, making a "redirect to action" or equivalent in AJAX call from grid.
I have tried to use an actionComplete event, but it's not working.
Could you help me?

11 Replies

PS Pavithra Subramaniyam Syncfusion Team March 5, 2019 09:15 AM UTC

Hi Jesús, 
 
Thanks for contacting Syncfusion support. 
 
Query: I get the data in controller and save correctly to database, returning a Json result. I need in a correct saved data controller operation, making a "redirect to action" or equivalent in AJAX call from grid. I have tried to use an actionComplete event, but it's not working. 
 
We have validated your query and created a sample based on your requirement. When update the edited data using update option, it will automatically redirect to (url provided in batchUrl)BatchUpdate method in controller. Please find the below code example and sample for your reference. 
 
[code example] 
<ejs-grid id="Grid" allowPaging="true"  toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })"> 
    <e-data-manager url="/home/UrlDatasource" batchUrl="/Home/BatchUpdate" adaptor="UrlAdaptor"></e-data-manager> 
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Batch"></e-grid-editSettings> 
    <e-grid-columns> 
        <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column> 
        <e-grid-column field="CustomerID" headerText="Customer ID" width="150"></e-grid-column> 
        <e-grid-column field="EmployeeID" headerText="Employee ID" width="130" textAlign="Right"></e-grid-column> 
        <e-grid-column field="ShipCity" headerText="ShipCity" width="120"></e-grid-column> 
    </e-grid-columns> 
</ejs-grid> 
 
... 
public IActionResult BatchUpdate([FromBody]CRUDModel batchmodel) 
        { 
            if (batchmodel.Changed != null) 
            { 
                for (var i = 0; i < batchmodel.Changed.Count(); i++) 
                { 
                    ... 
               } 
            } 
 
            if (batchmodel.Deleted != null) 
            { 
                for (var i = 0; i < batchmodel.Deleted.Count(); i++) 
                { 
                    order.Remove(order.Where(or => or.OrderID == batchmodel.Deleted[i].OrderID).FirstOrDefault()); 
                } 
            } 
 
            if (batchmodel.Added != null) 
            { 
                for (var i = 0; i < batchmodel.Added.Count(); i++) 
                { 
                    order.Insert(0, batchmodel.Added[i]); 
                } 
            } 
            var data = order.ToList(); 
            return Json(data);   
 
        } 
 
 
If it does not meet your requirement, please provide more information regarding your requirement.  
 
  • Do you want to create a Ajax call in actionComplete event to update the records.
  • What are you trying to achieve in actionComplete event?
 
Regards, 
Pavithra S. 



JM Jesús Mostajo March 11, 2019 08:55 AM UTC

Hi Pavithra

thank you for your response

I need redirect to another action when data is saved, but returning Json(Data) I get the same view.

I have tried return from controller an return RedirectToAction but it's not working.
Perhaps I have to do it by AJAX? I have tried use save data event but it's not working


PS Pavithra Subramaniyam Syncfusion Team March 11, 2019 09:38 AM UTC

Hi Jesús, 
 
Thanks for your update. 
 
You can achieve your requirement by sending an Ajax request to the required action inside the “actionComplete” event with “batchsave” request type. Please refer to the below code example, documentation link and sample link for more information. 
 
[index.cshtml] 
<ejs-grid id="Grid" actionComplete="complete" allowPaging="true"  toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })"> 
    <e-data-manager url="/home/UrlDatasource" batchUrl="/Home/BatchUpdate" adaptor="UrlAdaptor"></e-data-manager> 
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Batch"></e-grid-editSettings> 
    <e-grid-columns> 
        <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column> 
        . . . 
    </e-grid-columns> 
</ejs-grid> 
 
<script> 
    function complete(e) { 
        if (e.requestType == 'batchsave') { 
            var ajax = new ej.base.Ajax(); 
            ajax.url = "/Home/AfterSave"; 
            ajax.type = "POST"; 
            ajax.contentType = "application/json; charset=utf-8"; 
            ajax.send().then(function (data) { 
                console.log(data); 
            }); 
                } 
    } 
    </script> 
 
 
[controller.cs] 
 
public class HomeController : Controller 
    { 
        public IActionResult UrlDatasource([FromBody]DataManagerRequest dm) 
        { 
            IEnumerable DataSource = order; 
            .  .  . 
            return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource); 
        } 
 
        public IActionResult BatchUpdate([FromBody]CRUDModel batchmodel) 
        { 
            .  .  . 
            return Json(data); 
 
        } 
 
        public string AfterSave() 
        { 
            return "saved"; 
 
        } 
} 
 
 
 
 
If you are still facing any issue on this, please share the below details that will be helpful for us to provide a better solution as early as possible. 
 
  1. Share your Grid code.
  2. Share more details on your requirement
 
Regards, 
Pavithra S. 



JM Jesús Mostajo March 12, 2019 08:42 AM UTC

Thanks for your response but I still have the same error.
The actionComplete event doesn't raise.

This is the behaviour:
  1. When I save the Grid, the controller method "BatchUpdate" is called and save the data in database.
  2. "BatchUpdate" controller return the Json result.
  3. In this moment the grid reload data calling to controller method which is defined in grid url property. This make a reload data as a first time.
  4. The actionComplete event doesn't raise.
Thanks for your feedback

  <ejs-grid id="Grid" actionComplete="complete"
                            toolbar="@(new List<string>() { "Update", "Cancel" })"
                            load="gridLoad">
            <e-data-manager url="/Home/UrlDataSource/@Model.Id"
                            batchUrl="/Home
/BatchUpdate"
                            adaptor="UrlAdaptor"></e-data-manager>
            <e-grid-editSettings allowEditing="true"
                                 mode="Batch"
                                 showConfirmDialog="true" 
                                 showDeleteConfirmDialog="true">
            </e-grid-editSettings>
            <e-grid-columns>
                <e-grid-colum...


<script>
    function gridLoad(args) {
            // set your customize date format based on your column
            this.columns[2].format = { type: 'date', format: 'dd/MM/yyyy' };
         }

    function complete(e) {
        if (e.requestType == 'batchsave') {
            var ajax = new ej.base.Ajax();
            ajax.url = "/Home/AfterGridSave";
            ajax.type = "POST";
            ajax.contentType = "application/json; charset=utf-8";
            ajax.send().then(function (data) {
                console.log(data);
            });
        }
    }
</script>


public IActionResult UrlDatasource([FromBody]DataManagerRequest dm, int? id)
        {

....

return dm.RequiresCounts ? Json(new { result = data, count = data.Count }) : Json(data);
        }


public ActionResult BatchUpdate([FromBody]CRUDModel<ProjectTaskDegreeForecast> myObject)
        {

...

return Json(data);
        }


public string AfterGridSave()
        {
            return "saved";
        }


PS Pavithra Subramaniyam Syncfusion Team March 12, 2019 09:15 AM UTC

Hi Jesús, 
 
Greetings from Syncfusion. 
 
From your update, we suspect that you are using the EJ2 script version older than v16.3.22 from which we have provided the “batchsave” as request type for “actionComplete” event of bulk save. So we suggest to refer our latest script file(v16.4.55) to overcome the reported issue. 
 
 
Please contact us if you need any further assistance on this. 
 
Regards, 
Pavithra S. 



JM Jesús Mostajo March 12, 2019 10:39 AM UTC

Thanks but I still have the same issue.

Any idea?

These are the project references:

Screenshoot



PS Pavithra Subramaniyam Syncfusion Team March 12, 2019 11:06 AM UTC

Hi Jesús, 
 
Thanks for your update. 
 
Unfortunately, We could not get the screenshot you have shared in the incident. Could you please provide the Version details of Syncfusion package and Script file(ej2.min.js) in your application that will be helpful for further analysis. 
 
 
 
 
Regards, 
Pavithra S. 
 



JM Jesús Mostajo March 12, 2019 11:41 AM UTC

Hi Pavithra

these are our project dependencies and I attach the js file.

Nuget
  • Microsoft.AspNetCore.App (2.1.1)
  • Microsoft.EntityFrameworkCore.Design (2.1.1)
  • Microsoft.EntityFrameworkCore.SqlServer (2.1.1)
  • Microsoft.EntityFrameworkCore.Tools (2.1.1)
  • Microsoft.VisualStudio.Web.CodeGeneration.Design (2.1.1)
  • Newtonsoft.Json (11.0.2)
  • Syncfusion.EJ2.AspNet.Core (16.4.0.52)
SDK
  • Microsoft.NETCore.App (2.1.0)

Attachment: ej2.min.js_29a4b732.zip


PS Pavithra Subramaniyam Syncfusion Team March 13, 2019 05:02 AM UTC

Hi Jesús, 
 
Greetings from Syncfusion. 
 
We have found that the script file that you have shared is an old version of ej2 script. Could you please check the issue by replacing the script reference with the cdn link or installing the latest ej2 script files and refer it in your application. 
 
Please contact us if you need any further assistance on this. 
 
Regards, 
Pavithra S. 
 
 



JM Jesús Mostajo March 13, 2019 10:53 AM UTC

Great ! Now works fine !!

Thank you and sorry for inconvenience...


PS Pavithra Subramaniyam Syncfusion Team March 13, 2019 11:06 AM UTC

Hi Jesús,  

Thanks for your update. 

We are happy to hear that the provided information helped you. 

Please contact us if you need any further assistance. As always, we will be happy to assist you.  

Regards,  
Pavithra S. 


Loader.
Live Chat Icon For mobile
Up arrow icon