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.

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.

Article ID: Published Date: Last Revised Date: Platform: Control:
4102 02/19/2015 02/19/2015 ASP.NET MVC (Classic) Grid
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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.