I am using web api in my mvc application. I have a problem while calling web api using jquey.get function. Consider the following scenario:
I have 2 controller name:
- HomeMVCController
- TestAPIController (using mvc style routing i.e. api/{controller}/{action}/{id})
HomeMVC controller contains 2 actions
- Index
- About
TestAPI controller contains 1 action
- Get
When i was on Index view of HomeMVC controller i.e.
http://localhost:1025/Home
and when i call $.get("api/TestAPI/Get") from the browser it returns the expected json response.
But when i was on About view of HomeMVC controller i.e.
http://localhost:1025/Home/About
and when i call $.get("api/TestAPI/Get") from the browser it returns error, resource not found, and the resource it is trying to locate is:
http://localhost:1025/Home/About/api/TestAPI/Get
instead of
http://localhost:1025/api/TestAPI/Get
Why browser added Home/About in the url to api and why it is not added Home/Index when i was on Index view. On Index view why api call is working as expected and why not working on About view ??