How to pass an array of integers in Json mode actions?
Problem:
To pass an array or a list of integers from the view to post action.
Solution:
In order to pass the array value to the post action, you need to serialize the array value and pass the serialized data to the mapper action. In the post action, you can de-serialize the serialized data and use the data based on your requirement.
CSHTML
@{ int[ ] numbers={1,2,3,4,5}; } @(Html.Syncfusion().Grid<MvcApplication15.Models.Student>("GenericListGrid") .ActionMode(ActionMode.JSON) .EnableSorting() .EnablePaging() .Mappers(map => { map.Action("GridFeatures", new { numbersCollection = Newtonsoft.Json.JsonConvert.SerializeObject(numbers) }); }) ) |
CS
using System.Web.Script.Serialization; namespace Grid.Controllers { public partial class GridController: Controller { public ActionResult GridFeatures() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult GridFeatures(PagingParams args, string numbersCollection) { var numberdata = new JavaScriptSerializer().Deserialize(numbersCollection, typeof(int[ ]) ); return data.GridJSONActions< Student>(); } } } |
Note: Refer the System.Web.Script.Serialization library in the controller.