I have started some project based on ASP:NET MVC and JavaScript/jQuery. I am trying to make API call to my controller with $.ajax function, but I always get 404. I have Googled and tried a lot of different solutions, but again i get 404. I know this question is very often asked online, but again hope there won't be a lot of -1. I would appreciate any help, maybe I can't see tree because of forest.
Parameter "datas" is only string in JSON format.
My code is below:.
JavaScript call:
function checkValidId(datas) {
$.ajax({
url: 'api/UserInfo/Test/',
type: 'POST',
data: JSON.stringify(datas),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (valid) {
if (valid) {
console.log("HURAAAAY!!!");
} else {
console.log("OOOH NO YOU DON'T !!!");
}
}
});
}
My controller:
public class UserInfoController : ApiController
{
private DM_DBEntities1 db = new DM_DBEntities1();
[HttpPost]
public static string Test(string data)
{
return "H E L L L L O";
}
}
My WebApiConfig:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}