If you have a new project and want to create a project with MVC and WebAPI together, you just need to>
You could then learn enough from the tutorial (Your
First ASP.NET Web API) to define the API controller.
App_Start\WebApiConfig.cs:
using
System.Web.Http;class
WebApiConfig{ public
static
void Register(HttpConfiguration configuration) { configuration.Routes.MapHttpRoute("API Default",
"api/{controller}/{id}", new
{ id = RouteParameter.Optional }); }}
using
System.Web.Http;...}protected
void
Application_Start()
{ AreaRegistration.RegisterAllAreas();RegisterGlobalFilters(GlobalFilters.Filters); WebApiConfig.Register(GlobalConfiguration.Configuration); RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles);}