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