2016-04-17 13 views
0

私は角度とウェブAPIを学習していて、ルーティングで少し張り付いています。たとえば、次のlocalhost:53967/productsを使用して製品を表示したいとします。

私のアプリケーションファイルは以下の通りです。 (30)

また、次のようなIndex.cshtmlページセットがあります。

<div class="container"> 
    <div ng-view></div> 
</div> 

WebApiConfig

config.Routes.MapHttpRoute(
      name: "DefaultApi", 
      routeTemplate: "api/{controller}/{id}", 

      defaults: new { id = RouteParameter.Optional } 
     ); 

これは私のGlobal.asaxのは間違いかもしれない何404 を返しlocalhost:53967/products

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

    } 

を提出ですか?

よろしく

+0

localhost:53967 /#/ productsまたはlocalhost:53967/index#/ productsを確認したことがありますか。 –

答えて

1

はlocalhost:53967 /製品間違い何ができるか404を返しますか?

おそらくhttp://localhost:53967/productsの代わりにhttp://localhost:53967/api/productsを探しています。あなたは、ルートの宣言と一致していることを確認してください:

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

あそこにapi/接頭辞を持っているので、クライアントにもこれを尊重しなければなりません。

関連する問題