title: Calling ASP.NET Web API in jQuery from an Area
body: <p>I have an ASP.NET MVC project with an Area named MyArea. A View in there, Index, contains this javascript at the bottom (triggered during onclick of button):</p>
  
  <pre><code>&lt;script&gt;
      function x() {
          var url = WebApi.Url() + "orders";
          url = "http://localhost:43292/api/employees";
          $.ajax({
              type: "GET",
              contentType: "application/json",
              url: url,
              dataType: "json",
              success: function (result) {
                  alert(result);
              },
              error: function (xhr, err) {
                  alert(xhr.status);
              }
          });
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>the Web API is like this:</p>
  
  <pre><code>[Route("api/employees")]
  [HttpGet]
  public IEnumerable&lt;Employee&gt; Get()
  {
      List&lt;Employee&gt; employees = null;
  
      //... get employees
  
      return employees;
  }
  </code></pre>
  
  <p>but it is always returning "Resource not found". 
  I think it is a problem when it is inside an Area, as when I move the same script inside a View that is not in an Area, the Web API gets called succesfully.</p>
  
  <p>Can anyone shed some light on this? Thanks.</p>
  
  <p>Oh, and I am using MVC 5 if that helps.</p>
  
  <p><strong><h1>EDIT</h1></strong></p>
  
  <p>Looks like it works when I tried a bare bones project just as SBirthare said. And I think the problem lies when I alter the Area route config. As I want that Area to be the default page, I've remove the leading Area name in its route config. So from:</p>
  
  <pre><code>context.MapRoute(
      "Employee_default",
      "Employee/{controller}/{action}/{id}",
      new { controller = "Dashboard", action = "Index", id = UrlParameter.Optional }
  );
  </code></pre>
  
  <p>to</p>
  
  <pre><code>// No leading Employee
  context.MapRoute(
      "Employee_default",
      "{controller}/{action}/{id}",
      new { controller = "Dashboard", action = "Index", id = UrlParameter.Optional }
  );
  </code></pre>
  
  <p>Removing the leading Area name results in "Resource not found (404)" when calling Web API.</p>
  
  <p>So my question would be what can I do in this situation to make this work?</p>