Reputation: 281
There's a great thread running here: How to add Web API to an existing ASP.NET MVC (5) Web Application project?
Unfortunately, for me is having an error on WebApiConfig in Global.asax, so how can i fix this error i even installed nugets.
The name 'WebApiConfig' does not exist in the current context
Global.asax
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
WebApiConfig
public class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// WebAPI when dealing with JSON & JavaScript!
// Setup json serialization to serialize classes to camel (std. Json format)
var formatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
formatter.SerializerSettings.ContractResolver =
new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
}
}
Upvotes: 1
Views: 4373
Reputation: 17485
As you copied code from other project , you are merging web api in existing mvc project so many time two project have different namespace so you have to add namespace or change namespace of webapiconfig.
Upvotes: 2