當我試圖從SQL Server數據庫中檢索數據並且存在多個具有外鍵的表時,出現錯誤。ASP.NET MVC - 使用angularJS從SQL Server獲取數據
控制器:
private DbContext db = new DbContext();
public JsonResult GetAll()
{
var result = db.Books.ToList();
return Json(result, JsonRequestBehavior.AllowGet);
}
Service.js:
var Service = {};
Service.getAll = function() {
return $http.get('BooksModels/GetAll');
};
Controller.js:
getAll();
function getAll() {
ToshokanService.getAll()
.success(function (an) {
$scope.books = an;
console.log($scope.books);
})
.error(function (error) {
$scope.status = 'Error' + error.message;
console.log($scope.status);
});
}
錯誤: 「Errorundefined」
這工作時,我只有數據庫中有一張表。
在ASP.NET MVC中使用AngularJS從數據庫檢索數據是一個好主意嗎?
有什麼錯誤?你到底在哪裏得到錯誤? – Sefa
錯誤:「Errorundefined」。在GET http:// localhost/BooksModels/GetAll – VMG
因此,當數據庫中有兩個表時,您遇到了這個問題?你有沒有調試你的控制器?如果有多個表,你能確認你的mvc控制器從數據庫中獲取數據嗎? – Sefa