Ich versuche, ein webapi+angularjs+mvc
Projekt zu entwickeln .hier Sie meine apicontroller
Die api-Controller in mvc nicht
public class DefaultController : ApiController
{
testDBEntities a = new testDBEntities();
public IEnumerable<City> Get()
{
return a.Cities;
}
}
Hier sehen Sie die webapiconfig
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
Aber sehen kann, wenn Ich tippe dies: localhost:5411/api/default
Ich habe diesen Fehler:
GlobalConfiguration.Configure(WebApiConfig.Register) in your Global.asax.cs file
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /api/default
Welche Version von WebAPI registrieren verwenden Sie? –
@AlexArt. Wie kann ich die Version finden? –
Verwenden Sie immer {action} in Ihrem Routenpfad wie - routeTemplate: "api/{controller}/{action}/{id}". Wenn Sie nicht {action} angeben, können Sie nicht mehrere get-Methoden in Ihrem Controller haben –