Posting data of a grid

Hi,

I have a webform with many control and a Editable Grid.
I need to know how to retreive data items from the grid in my Controller Action when I submit my form.

Thank you

3 Replies

RS Renjith Singh Rajendran Syncfusion Team April 19, 2018 07:21 AM UTC

Hi Tommy, 

Thanks for contacting Syncfusion support. 

We suspect that you would like to pass the data to the controller to perform CRUD operations. We suggest you to make use of the URL Adaptor. This will allow you to send post to the server side while performing the CRUD operations. Please refer the documentation links below for more information, 

Documentations : 

In the above documentations, we have explained the topic in ASP.NET MVC platform with Razor codes. As you have mentioned as “webform” in your update, please confirm the platform(Razor codes or aspx codes) you are using. So that based on this we can assist you further.  

Since we are not certain about your requirement. Please provide  the following details for better assistance. 

  1. Share detailed description of your requirement.
  2. Share full Grid code example.

The provided information will help us to analyze the issue and provide you the response as early as possible. 

Regards, 
Renjith Singh Rajendran. 



TM Tommy Mailhot April 19, 2018 02:08 PM UTC

We use ASP.NET MVC platform with Razor.

When I talk about "webform", I didn't use the good word. I want to refer to Htlm Form <form> I use to post all the stuff of the page.

I understand the possibility of using CRUD operation directly on the grid but in specific situation, I need to post all the data of the page in a sigle operation.
In this case, I need to receive all data in a Viewmodel directly in the action of my controller.




RS Renjith Singh Rajendran Syncfusion Team April 20, 2018 01:12 PM UTC

Hi Tommy, 

We suspect that you would like to pass the entire Grid’s dataSource to the controller side on submit action. We suggest you to pass the entire datasource of Grid using Ajax post to the controller. Please refer the below code example, 

<form> 
    @Html.EJS().Button("refresh").Content("Refresh").Render() 
    @Html.EJS().Grid("Grid").DataSource((IEnumerable<object>)ViewBag.dataSource).Columns(col => 
                 { 
                     col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("150").Add(); 
                     ... 
                 }).AllowFiltering().EditSettings(e => e.AllowEditing(true).AllowDeleting(true)).Render() 
</form> 
<script> 
   document.getElementById("refresh").addEventListener("click", () => { 
        var grid = document.getElementById("Grid").ej2_instances[0]; 
       $.ajax({ 
            url: "/Home/Data", 
            type: "POST", 
            datatype: "json", 
            contentType: "application/json; charset=utf-8", 
            data: JSON.stringify({ gid: JSON.stringify(grid.dataSource) }), 
            success: function (result) { 
                debugger; 
            } 
        });  
    }) 
</script> 
 
[HomeController.cs] 
 
public ActionResult Data(string gid) 
        { 
            return Json(gid, JsonRequestBehavior.AllowGet); 
        } 

Please refer the screenshot below, 
 

We have achieved your requirement by using a button click event. When the button is clicked the ajax post will be made, in that we have passed the entire Grid  datasource. We have also prepared a sample, based on this requirement which could be downloaded from the link below, 



Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 


Loader.
Up arrow icon