2016-11-26 79 views
0

我試圖從我的mvc項目中的另一個文件夾(AddEditPersonModal.cshtml)訪問編輯部分,然後通過角度加載內容在ui bootstrap模態中。當index.cshtml頁面加載時,我得到了一個404錯誤,非常偏袒。這裏是我的代碼:Angular MVC項目 - 獲取404 with templateUrl

角:

$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:

[HttpPost] 
    public ActionResult AddEditPersonModal(DTOPerson model) 
    { 
     return View(model); 
    } 
+0

什麼是你'AddEditPersonModal.cshtml'文件的路徑? – 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()方法去除[HttpPost]屬性(它使一個GET請求,不POST)