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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to pass an array of integers in Json mode actions?

Platform: ASP.NET MVC (Classic) |
Control: Grid |
Published Date: February 19, 2015 |
Last Revised Date: February 19, 2015
Tags:

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.

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon