NerdyDriod
NerdyDriod

Reputation: 77

What is my controller action(.NET 6.0) and AJAX call returning 500 error?

I have an ajax call (GET) to a controller action to generate and return a url (JSON). When I run the code the ajax call goes but it never hits the controller action. I get a 500 error with no response text. I'm stumped. Below is my code, Thanks!

    [HttpGet] 
    public ActionResult ViewOrderForm(int? id)
    {
        if (id == null || id == 0)
        {
            _logger.LogInformation("Order Id " + id + " does not exisit in the database. User is unable to view form.");
            return NotFound("Order Id " + id + " does not exisit in the database.");
        }

        return Json(new
        {
            newUrl = Url.Action("ViewOrder", new { id = id })
        }
        );

    }

function viewOrderForm(id) {
$.ajax({
    url: siteURLS.ViewOrderForm,
    method: "GET",
    data: {
        id: id
    },
    error: function (e) {
        alert("Unable to open ITO form. " + e.responseText);
    }
}).done(function (data) {
    //alert(data.newUrl);
    window.location.replace(data.newUrl);
});
}

Upvotes: 0

Views: 299

Answers (2)

Serge
Serge

Reputation: 43959

try this ajax,

 $.ajax(
 {
  url: siteURLS.ViewOrderForm+"?id="+id,
  type: 'GET', 
  dataType: 'json',
 success: function (data) {
     window.location.replace(data.newUrl);
},
 error: function (e) {
        alert("Unable to open ITO form. " + e.responseText);
    }
 });

Upvotes: 0

WisdomSeeker
WisdomSeeker

Reputation: 934

Believe its type instead of method in ajax property

Upvotes: 2

Related Questions