title: Web API 2 not working (404)
body: <p>i have been trying for a long time get Web API 2 working. I have read a lot of articles and posts over internet, but so far i have been unlucky.</p>
  
  <p>I just need to get working simple Web API method, but for some reason i am still getting 404 method not found. I really dont know now, where problem can be as it seems to me everything is ok.</p>
  
  <p>I have tried a lot of variations of attributes, configs and so on. I have end up with this code:</p>
  
  <p>Global.asax</p>
  
  <pre><code>AreaRegistration.RegisterAllAreas();
  FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
  RouteConfig.RegisterRoutes(RouteTable.Routes);
  
  GlobalConfiguration.Configure(WebApiConfig.Register);
  </code></pre>
  
  <p>WebApiConfig.cs</p>
  
  <pre><code>config.MapHttpAttributeRoutes();
  
  config.Routes.MapHttpRoute(
      name: "DefaultApi",
      routeTemplate: "api/{controller}/{id}",
      defaults: new {  id = RouteParameter.Optional }
  );
  
  var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(x =&gt; x.MediaType == "application/xml");
  config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
  </code></pre>
  
  <p>ApiController</p>
  
  <pre><code>public class ContactFormController : ApiController
  {
      [Route("~/api/sendemail")]
      [HttpPost()]
      public IHttpActionResult SendEmail(ContactFormModel contactForm)
      {
          return Ok();
      }
  }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>public class ContactFormModel
  {
      public string Name { get; set; }
      public string Email { get; set; }
      public string Subject { get; set; }
      public string Message { get; set; }
  }
  </code></pre>
  
  <p>jQuery Code</p>
  
  <pre><code>var jsonData = { "Name": name.val(), "Email": email.val(), "Subject": subject.val(), "Message": comment.val() };
  
  $.ajax({
      url: "api/sendemail",
      type: "POST",
      data: jsonData,
      cache: false,
  
      ...
  });
  </code></pre>
  
  <p>As you can see, it is MVC 5 + Web API 2.</p>
  
  <p>Thanks for help. So simple thing and nothing is working.</p>