[RESOLVED]MVC web api routing issues

This is driving me mad i cant understand why it wont work.

The MVC project is split into areas and in one of the areas registration there is

        public override void RegisterArea(AreaRegistrationContext context) 
        {
            context.Routes.MapHttpRoute(
                "API",
                "API/{action}",
                new { controller = "API" });
         
   context.MapRoute(
                "FrontEndSites_default",
                "{controller}/{action}/{id}",
                new { controller = "Dashboard", action = "Index", id = UrlParameter.Optional }
            );
        }

The bottom one works fine its just the api one that doesnt work.

I have this Api Controller

    public class APIController : ApiController
    {
        [HttpGet]
        public int apiTest()
        {
            return 5;
        }

}

and on a webpage this js:

    $.ajax({
        url: "/API/apiTest",
        data: "",
        type: "GET", dataType: 'json', async: false,
        success: function (data)
        {
            alert(data);
        },
        error: function () { alert('ajax error'); }
    });

When i do something to run that javascript it tries to communicate with the server with url : 
http://localhost:53531/API/apiTest    with the response is 404.

There is no other routes set up in the project except for the ones above, there is only 1 area and nothing set up at the root level (outside any areas).

Thanks,

Paul

I’ve found the problem now, there was another route elsewhere in the project after all that it was matching to before getting to the one i wanted it to match to.

Hi Puma613,

If you have the issue about Web API, I suggest that you should post it to the
Web API forum
.

There is a link about Web API that may benefit you:

# Configuring ASP.NET Web API 2

http://www.asp.net/web-api/overview/advanced/configuring-aspnet-web-api

Best Regards

Starain

Leave a Reply