$ http.get()未找到web api controller ..resource未找到

时间:2016-01-08 02:09:15

标签: angularjs rest asp.net-web-api

我从angular调用web api控制器,我收到资源未找到异常。电话未到达我的控制器。谢谢。这是我的代码

[HttpGet, Route("api/triangle")]
        public string Get()
        {

            return "Please enter all sides.";
        }



$http.get("/api/Triangle").success(function (data) {

            $scope.resulttriangle = JSON.parse(data);

        });

  config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

2 个答案:

答案 0 :(得分:0)

 protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        GlobalConfiguration.Configure(WebApiConfig.Register);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }

答案 1 :(得分:0)

我认为有一个错字。您已将路线定义为"api/triangle,并且您正在尝试"api/Triangle