2017-06-12 14 views
0

角度ルートプロバイダに問題があります。 app.jsルートの設定では:AngularJS Routeproviderを使用しているときにASP.NET mvcアクションにリクエストできません

fmApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider){ 
$locationProvider.html5Mode(true); 
$routeProvider.when('/', { 
    templateUrl: 'staticViews/home.html, 
    controller: 'fmController' 
}).otherwise({ redirectTo: '/' }) 
}) 

、私のweb.configファイルで、私はindex.htmlをするすべての要求をリダイレクトするURLを書き換える:index.htmlをで

</system.webServer> 
    <rewrite> 
     <rules> 
     <rule name="Rewrite Url to layout.html"> 
      <match url=".*\.html|css/|img/|js/|data/|lib/|templates/|favicon.ico" negate="true" /> 
      <action type="Rewrite" url="layout.html" /> 
     </rule> 
     </rules> 
    </rewrite> 
    </system.webServer> 

私は形をしましたそれが提出したとき、私はそれが$ HTTP

$scope.submit = function(){ 
    $http({ 
     method:'post', 
     url: '/api/test', 
     data: JSON.stringify(
     angular.copy($scope.data) 
    ) 
    }) 
} 

私の問題は、私は、API /テスト/に要求したとき、それは、サーバsの呼び出しではありませんを使用して、サーバー側のアクションに依頼したいですide(api-controllerとtest-action)はlayout.htmlを呼び出します(web.configに書き直すため)。暗闇の中でだけでショット

+0

コンソールエラーが発生しましたか? –

+0

暗闇の中でちょうど撃たれましたが、あなたのAPIが書き換え否定に含まれていないように見えます。おそらく "。* \ .html | api/| css/| img/| js/| data/| lib/| templates/| favicon.ico"おそらく? – Dillon

+0

@Dillon Wow !!それは完全に働く。大いに感謝する! – vantrung1408

答えて

0

.... http://localhost/#!/が、あなたのAPIが書き換えネゲートに含まれていないように見える:私はないrewrite url in web.config$locationProvider.html5Mode(true);を使用している場合は、私のURLを元に#を表示します。多分試してみる

<match url=".*\.html|api/|css/|img/|js/|data/|lib/|templates/|favicon.i‌​co" negate="true" /> 

おそらく?

関連する問題