Vikram
Vikram

Reputation: 181

Error 500 on ajax call to controller - MVC Razor

My controller :

    [HttpGet]
    public ActionResult canEdit(List<string> mylist)
    {
        if (SomeProgramLogic)
        {
            return Content("Y");
        }

        return Content("N");
    }

My ajax Call :

    var getData = { mylist : myArray}; // An array created in the client side

    $.ajax({
        type: "GET",
        url: "canEdit",
        data: getData,
        success: function (data) {
            alert(data); 
        },
        dataType: "json",
        traditional: true
    });

The debugger enters my controller . mylist contains the exact data . At no point I see an error or an exception. But I get this error "Failed to load resource: the server responded with a status of 500 (Internal Server Error) and the alert message does not pop up.

My rendered url format

      http://localhost/Controller/canEdit?mylist=a&mylist=a&mylist=b 

Upvotes: 3

Views: 2300

Answers (1)

Vikram
Vikram

Reputation: 181

I changed my controller return value to

     return Json("N", JsonRequestBehavior.AllowGet); 

and this solved the issue. Thanks @TrueBlueAussie for the pointer.

Upvotes: 2

Related Questions