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.
Unfortunately, activation email could not send to your email. Please try again.

Submit (POST) of the entire grid

Thread ID:

Created:

Updated:

Platform:

Replies:

118650 Mar 29,2015 02:23 AM Feb 2,2017 12:51 AM ASP.NET MVC 5
loading
Tags: Grid
Martin
Asked On March 29, 2015 02:23 AM

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.






Ajith R [Syncfusion]
Replied On March 30, 2015 09:42 AM

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: http://www.syncfusion.com/downloads/support/forum/118650/AjaxFormPostGrid1793574874.zip

Please let us know if you have any concerns.

Regards,

Ajith R


Martin
Replied On March 31, 2015 02:16 AM

Thanks you very much,

Exactly what I was looking for!

Ajith R [Syncfusion]
Replied On April 1, 2015 12:55 AM

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


Khaled
Replied On February 1, 2017 12:02 PM

it helped me too!

Ragavee U S [Syncfusion]
Replied On February 2, 2017 12:51 AM

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


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.

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.

;