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
close icon

Submit (POST) of the entire grid

Hi,

I'm using the Grid (ASP.NET MVC 5), I'm trying to Post back to my controller the complete values of a Grid.


I need to use the @Ajax.BeginForm helper to submit the form.  I plan on starting with an empty grid (if that matter).


Can you please provide an simple example of doing so?  Just like 2 column, nothing fancy  I'm having a hard time!  (I can provide my code if needed).

Thanks,
Appreciated.






5 Replies

AR Ajith R Syncfusion Team March 30, 2015 01:42 PM UTC

Hi Martin,

Thanks for using Syncfusion products.

Query: Ineed touse the @Ajax.BeginForm helper to submit the form. Can you please provide an simple example of doing so?

We suggest you to get the Grid dataSource as serialized string in the submit button click event and pass it to the controller by using hidden input element in the Ajax.BeginForm method to achieve your requirement. Please refer the below code snippet for further details.

[cshtml]

@using (Ajax.BeginForm("GetOrders", "Grid", null, FormMethod.Post))

{

@(Html.EJ().Grid<AjaxFormPostGrid.OrdersView>("Grid")

.Datasource((IEnumerable<object>)ViewBag.datasource)

.AllowPaging()

.Columns(col =>

{

-------

-------

})

)

<button type="submit" onclick="complete();">Get DataSource</button>

<input type="hidden" name="dataSource" value="" id="data" />

}

<script type="text/javascript">

function complete() {

var gridobj = $("#Grid").data("ejGrid");

var val = JSON.stringify(gridobj.model.dataSource); // Serialized the grid dataSource

$("#data").val(val); // Set the dataSource to hidden element

}

</script>

[controller]

public ActionResult GetOrders(string dataSource)

{

// Code here for deserializing the dataSource

var deserializedObj = (List<OrdersView>)Newtonsoft.Json.JsonConvert.DeserializeObject(dataSource, typeof(List<OrdersView>));

return RedirectToAction("GridFeatures");

}

For your convenience we have created a simple sample and the same can be downloaded from the belwo link.

Sample Link: https://www.syncfusion.com/downloads/support/forum/118650/AjaxFormPostGrid1793574874.zip

Please let us know if you have any concerns.

Regards,

Ajith R



MA Martin March 31, 2015 06:16 AM UTC

Thanks you very much,

Exactly what I was looking for!


AR Ajith R Syncfusion Team April 1, 2015 04:55 AM UTC

Hi Martin,

Thanks for your update.

We are happy to hear that your requirement has been achieved in your end.

Please get back to us if you have any other concerns.

Regards,
Ajith R



KH Khaled February 1, 2017 05:02 PM UTC

it helped me too!


RU Ragavee U S Syncfusion Team February 2, 2017 05:51 AM UTC

Hi Khaled, 
  
Thanks for your update. 
 
Regards, 
Ragavee U S. 


Loader.
Live Chat Icon For mobile
Up arrow icon