Wie man Ajax-gepostet Array in meinem C# - controller?

Arbeite ich mit ASP.NET-MVC. Ich versuche, nach einem array an ajax, aber ich weiß nicht, wie man es in meinem controller. Hier ist mein code :

Ajax

var lines = new Array();
lines.push("ABC");
lines.push("DEF");
lines.push("GHI");
$.ajax(
{
    url: 'MyController/MyAction/',
    type: 'POST',
    data: { 'lines': lines },
    dataType: 'json',
    async: false,
    success: function (data) {
        console.log(data);
    }
});

MyController

public JsonResult MyAction(string[] lines)
{
    Console.WriteLine(lines); //Display nothing
    return Json(new { data = 0 });
}

Warum kann ich nicht sehen, meine Zeilen ? Wie man richtig post dieses array und verwenden Sie es in MyAction ?

  • Versuchen Sie, mit traditional: true ajax-Einstellungen parameter.
  • Versuchen { 'lines' : JSON.stringify(lines)
InformationsquelleAutor Alex | 2013-11-04
Schreibe einen Kommentar