Home > DeveloperSection > Forums > Passing array from ajax to controller
jacob rasel
jacob rasel

Total Post:88

Points:616
Posted on    January-25-2014 1:38 AM

 C# C# 
Ratings:


 1 Reply(s)
 1154  View(s)
Rate this:

I am trying to pass an array variable from ajax to controller, but I am not getting the values in controller

below is my code

AJAX

 function userDetailsClass() {

          var userDetails = {};

          userDetails.age = 12;

          userDetails.Name = "Vignesh";

          userDetails.lastName = "s";

          debugger;

          $.ajax({

              url: "Home/userDetails",

              data: JSON.stringify({

                  UserDetailsParam: userDetails

              }),

              responseType: "json",

              success: successfn,

              error: errorfn

          });

          function successfn(result) {

          };

          function errorfn(result) {

          };

      }

Controller

public ActionResult userDetails( string UserDetailsParam){

            return View();

        }

I also tried

public ActionResult userDetails( string[] UserDetailsParam){

            return View();

        }



Pravesh Singh

Total Post:411

Points:2881
Posted on    January-25-2014 1:52 AM

Hi Jacob,

Your code should be like this

     $.ajax({

          url: "Home/userDetails",

          data: {

              "UserDetailsParam":JSON.stringify(userDetails)//change this

          },

          responseType: "json",

          success: successfn,

          error: errorfn

      });


Don't want to miss updates? Please click the below button!

Follow MindStick