-1

I send data by ajax to mvc controller. I get to the correct method but without data. I tried to get List<string> but its null

js code:

function sendDataCreateMilestone(parameters) {
    $.ajax({
        url: "/QRCNew/create",
        type: "post",
        dataType: "json",
        data: JSON.stringify(parameters)
    });
}

server:

here i revived all the time null

public ActionResult Create (List<string> ids, string collection)
{
    do....
}
Tieson T.
  • 20,774
  • 6
  • 77
  • 92
  • 3
    What are the "parameters"? – Sajal Jun 28 '15 at 12:45
  • You can refer this. It's exactly your problem. http://stackoverflow.com/questions/309115/how-can-i-post-an-array-of-string-to-asp-net-mvc-controller-without-a-form[1] [1]: http://stackoverflow.com/questions/309115/how-can-i-post-an-array-of-string-to-asp-net-mvc-controller-without-a-form – hungndv Jun 28 '15 at 13:02
  • @Dev-One - parameter is array. I can see my data being send to server from client but the server doesn't receive it – Eugene Sergienko Jun 28 '15 at 19:54
  • You need to show what `parameters` is –  Jun 29 '15 at 03:43

1 Answers1

-1

I found my mistake , correct answer is

function sendDataCreateMilestone(parameters) {
    $.ajax({
        url: "/QRCNew/create",
        type: "post",
        dataType: "json",
        data: { collection: parameters }
    });
}

server:

  public ActionResult Create (string collection)
        {
            do ...
        }
  • $.ajax does not work for me. I have to use XMLHttpRequest and then it only sends null. This should be easy and yet Microsoft has made it incredibly difficult – Paul McCarthy May 06 '19 at 12:16