2
In my visual studio 2012, I have a solution with several projects and one of them is web. In this project, I would like to include a "Web Api Controller" class to do some tests.
I created a class with the name Valuescontroller, with all the necessary methods. I created a page. aspx simple and put the ajax code to call the api, however, the browser gives the answer that could not find the resource you needed (/View/api/Values).
When I do exactly the same thing on a new web project, the system runs smoothly.
Has anyone ever faced this problem or even manages to help?
Follows details:
Method of Global.asax.Cs
void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = System.Web.Http.RouteParameter.Optional }
);
}
Jquery function for calling the server method:
ValuesController.cs
Project structure
Post more details of the error. You can create a web project with API specification becomes easier. Is your ajax request post or get? your method accepts both? Generally the error "failed to find the resource you needed" happens for several reasons, post the method code. Try to clean the project and restart the visual studio. Sometimes it gives error in recompiling and ends up saying that the feature does not exist!
– Premiere
Oops. So, starting a new project won’t help me, because I really want to make some improvements in this one that already exists. When I create a new one, it runs smoothly. I will post the code.
– Eduardo
Post the method you are testing and your ajax request!
– Premiere
I posted, but as I said, if I create a new solution, with a web project and put exactly the same code with the same structure, it works perfectly.
– Eduardo
When you return json content?
– Premiere
Premiere, thanks for the help. My mistake was on my route, which did not have the address of the subfolder. My routeTemplate should look like this: "View/api/{controller}/{id}". Anyway, thank you very much for your attention.
– Eduardo
json is the date Premiere.
– Eduardo