There were many suggested questions/answers when adding this. I went through a bunch and none seemed to help.
I am sure I am missing something simple, just can't see it.
I have an existing ASP.Net MVC (V5) Site. It's a single page.
I am adding an API Controller (WebAPI 2) to it to handle some ajax posts.
I can't seem to get past the 404 Error when trying to post to my controller.
I am also using Attribute Routing.
Here are the parts of the code I believe you will need to see:
API Controller
[RoutePrefix("api/services")]
public class ServicesController : ApiController
{
[HttpPost]
[Route("contact")]
public HttpResponseMessage SendContact(ContactModel model)
{
return Request.CreateResponse(HttpStatusCode.OK, true);
}
}
WebApiConfig - couple of parts commented out as i try things.
public class WebApiConfig
{
public static void Register(HttpConfiguration configuration)
{
configuration.MapHttpAttributeRoutes();
//configuration.Routes.MapHttpRoute("API Default", "api/{controller}/{id}",
// new { id = RouteParameter.Optional });
}
}
And my global.cs - again commented out things i've tried
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
//WebApiConfig.Register(GlobalConfiguration.Configuration);
BundleConfig.RegisterBundles(BundleTable.Bundles);
GlobalConfiguration.Configure(WebApiConfig.Register);
When attempting to post to the api i receive:
POST http://localhost:8085/api/services/contact 404 (Not Found)
Any idea what I am missing?