1

Here is my array:

{latlng: [{lat: 41.9841092242239, lng: -87.6459866168}, {lat: 41.948650308164744, lng: -87.64431828280067}, {lat: 41.94833112697515, lng: -87.644017875391}]

Here is my javascript code:

 var postedData = JSON.stringify({
 latlng: boundaries
 });
 alert("here are your boundaries so far : " + postedData);
 $.ajax({
 url: '/Communities/UpdateBoundaries',
 type: "POST",
 traditional: true,
 contentType: "application/json",
 data: postedData,
 datatype: "json",
 success: function () {
 console.log('success!!');
 }
 });
 }

and here is my controller: where boundaries is my incoming array of latlng, but it is coming in null.

 [HttpPost]
 public ActionResult UpdateBoundaries(List<latLng> boundaries)
 {
 return View();
 }
asked Mar 22, 2017 at 20:10
0

1 Answer 1

2

Change

var postedData = JSON.stringify({latlng: boundaries});

to

var postedData = JSON.stringify(boundaries);

This is because the action parameter is an array. If it were a type that contained an array property with property name latlng then you pass it in the same manner you did in your existing code.

answered Mar 22, 2017 at 20:13

5 Comments

i received an error on JSON.Stringify not a function
@PaulT.Rykiel - lowercase s in stringify. javascript is case sensitive.
@PaulT.Rykiel - you are running this in a browser right? Try re-typing it as maybe it was not copied from the browser correctly: JSON.stringify.
Nevermind, I don't know what I did wrong before, but this time it worked.
@PaulT.Rykiel - good deal! If this solves your problem please consider marking it as the answer.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.