I am attempting to call my Web API with a getJSON request:
var uri = 'api/comment';
var id = solicitorId;
$.getJSON(uri, id, (function (data) {
$('#commentTableContainer').html(data);
}));
And this is the method in the comment Controller class:
public string GetComment(int id)
{
//Do things
}
I am using the default routing:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { action = "Index", id = UrlParameter.Optional }
);
However, when trying to call the api with getJSON I receive a 405 error:
HTTP405: BAD METHOD - The HTTP verb used is not supported.
(XHR)GET - http://localhost:<port>/api/comment?334203
The GET request works if I remove the id parameter from GetComment signature, i.e. GetComment()
I don't know too much about this WebAPI stuff - I mostly followed a guide from Microsoft, here here (docs.microsoft.com)
If anyone has any ideas I would be grateful. I've looked at many SO questions on this, but none have helped.
I've tried adding [HTTPGet] to the CommentController GetComment(int id) method, as well as specifying the route with [Route] but I am getting nowhere at all.
Any help would be much appreciated. Thanks.