2016-11-26 2 views
0

私はmvcプロジェクト内の別のフォルダ(AddEditPersonModal.cshtml)から編集部分にアクセスしようとしていますが、その内容をUIブートストラップモーダルでロードします。 index.cshtmlページが読み込まれると、その部分的に404エラーが発生します。角度角度MVCプロジェクト - templateUrlで404を取得する

$scope.editPerson = function (person) { 
    $scope.modalModel = person; 
    //getModal(person); 
    $uibModal.open({ 
     templateUrl: '/Modal/AddEditPersonModal.cshtml', 
     controller: 'modalController', 
     scope: $scope 
    }) 
    resolve: { 
      person: { 
       return $scope.person; 
      } 
    } 
} 

Index.cshtml

<a href="" data-toggle="modal" data-target="#myModal" ng-model="editPersonModel" ng-click="editPerson(person)"><span class="fa fa-pencil-square-o"></span></a> 

エラー:

angular.js:12011 GET http://localhost:58227/Modal/AddEditPersonModal.cshtml 404 (Not Found)(anonymous function) @ angular.js:12011n @ angular.js:11776(anonymous function) @ angular.js:11571(anonymous function) @ angular.js:16383$eval @ angular.js:17682$digest @ angular.js:17495scopePrototype.$digest @ hint.js:1364$apply @ angular.js:17790scopePrototype.$apply @ hint.js:1427(anonymous function) @ angular.js:25890dispatch @ jquery-1.12.4.min.js:3r.handle @ jquery-1.12.4.min.js:3 
angular.js:13920 Error: [$compile:tpload] http://errors.angularjs.org/1.5.8/$compile/tpload?p0=%2FModal%2FAddEditPersonModal.cshtml&p1=404&p2=Not%20Found 
    at angular.js:38 
    at angular.js:19433 
    at angular.js:16383 
    at m.$eval (angular.js:17682) 
    at m.$digest (angular.js:17495) 
    at m.scopePrototype.$digest (hint.js:1364) 
    at m.$apply (angular.js:17790) 
    at m.scopePrototype.$apply (hint.js:1427) 
    at l (angular.js:11831) 
    at J (angular.js:12033) 

ModalController:

ここに私のコードです
+0

から[HttpPost]属性を削除しますか? – Sravan

+0

〜Views/Modal/AddEditPersonModal.cshtml vs2015でデバッガを実行すると、それが私にかかるパスです... – tshoemake

+0

'template-url'はアプリケーションのルートパスからの相対パスでなければなりません。たとえば、あなたのビューがルートにある場合は、使用します。 'Views/Modal/AddEditPersonModal.cshtml'、 – Sravan

答えて

1

MVCでは、ビューファイル自体ではなく、ビューを返すコントローラメソッドに移動します。

$uibModal.open({ 
    templateUrl: '/Modal/AddEditPersonModal', // amend 
    controller: 'modalController', 
    scope: $scope 
}) 

にスクリプトを変更し、あなたの `AddEditPersonModal.cshtml`ファイルのパスが何であるかを、あなたのAddEditPersonModal()方法(それはGETリクエストではなく、POSTを作っている)

関連する問題