W
W
wkololo_4ever2014-05-12 10:36:33
JavaScript
wkololo_4ever, 2014-05-12 10:36:33

Why is JSON data not being parsed?

There is a JS code that sends data to the controller

function () {
            console.log(JSON.stringify(allPoint));
            $.ajax({
                type: "POST",
                data: JSON.stringify(allPoint),
                url: "/Gis/SavePoint",
                success: function () {

                }

            });
        }

On the controller side I receive data
public ActionResult SavePoint(List<NewPoint> allPoint)
        {
            return View();
        }

NewPoint class
public class NewPoint
    {
        public string X { get; set; }
        public string Y { get; set; }
    }


I set a breakpoint, allPoint is always null. What am I doing wrong?
string console.log(JSON.stringify(allPoint)); outputs data in the form
[{"X":456,"Y":208},{"X":238,"Y":183},{"X":280,"Y":263},{"X":360,"Y":253}]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yago, 2014-05-12
@wkololo_4ever

contentType: 'application/json',
dataType:  'json'

In the parameters of the ajax call, try to register. jQuery default data as application/x-www-form-urlencoded sends

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question