Showing posts with label MVC. Show all posts
Showing posts with label MVC. Show all posts

21 February, 2014

Pass Javascript Array to Controller via AJAX in MVC


Create JavaScript Array: 
var stringArray = new Array();
stringArray .push("1");
stringArray .push("2");
stringArray .push("3");
Ajax Call:
    $.ajax({
        type: 'POST',
        url: '/Controller/View',
        traditional: true,
        dataType: "json",
        data: { methodParam: stringArray },
        success: function (data) {
            alert("success");
        },
        error: function (args) {
            alert("Error on ajax post");
        }
    })
Controller: 
[HttpPost]
public ActionResult TutorAvailability(string[] methodParam)