I've just installed Visual Studio 2012 and started checking out MVC 4 and Web Api. I've created a new MVC 4 app with Web API. Based on some examples and tutorials I started configuring my routes with:
routes.MapHttpRoute( name: "Controller only", routeTemplate: "api/{controller}" );
However, that results in an error that RouteCollection
doesn't contain a definition for MapHttpRoute
. Am I missing some DLLs installed? As far as I could see I have all the right DLLs and version installed.
Web API 2 supports a new type of routing, called attribute routing. As the name implies, attribute routing uses attributes to define routes. Attribute routing gives you more control over the URIs in your web API.
If you are familiar with ASP.NET MVC, Web API routing is very similar to MVC routing. The main difference is that Web API uses the HTTP verb, not the URI path, to select the action. You can also use MVC-style routing in Web API.
Action method name can be the same as HTTP verbs like Get, Post, Put, Patch or Delete as shown in the Web API Controller example above. However, you can append any suffix with HTTP verbs for more readability. For example, Get method can be GetAllNames(), GetStudents() or any other name which starts with Get.
I have solved it by adding a reference to System.Web.Http
in RouteConfig.cs
Try referencing: System.Web.Http and System.Web.Http.WebHost.dll
Then add a using statement for namespace: System.Web.Http
Note: It could also be that your intellisense is acting up. In which case just go ahead and type your code manually and build.
Hope that helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With