【发布时间】:2015-08-19 21:12:42
【问题描述】:
{{project.ProjectName}} 在我的浏览器中没有显示任何数据。我在数据库中有数据,在我的_Layout 中有所需的脚本文件,在正文中有ng-app="myApp"。调试控制器确实返回 1 行数据。不知道我做错了什么。它应该显示 1 行的 ProjectName。
控制器:
public ActionResult Index()
{
return View();
}
public JsonResult GetAllProjects()
{
EEDBEntities db = new EEDBEntities();
var result = db.Projects.ToList();
return Json(result, JsonRequestBehavior.AllowGet);
}
App.js:
var myApp = angular.module('myApp', []);
myApp.controller('mainController', function($scope, $http) {
$http.get('/home/GetAllProjects')
.success(function(result) {
$scope.projects = result;
})
.error(function(data) {
console.log(data);
});
});
Index.cshtml:
<h3>
All Projects
</h3>
<div ng-controller="mainController">
<table class="table table-striped">
<tr ng-repeat="project in projects">
<td>{{project.ProjectName}}</td>
<td class="text-right">
<button class="btn-danger">X</button>
</td>
</tr>
</table>
</div>
【问题讨论】:
-
您能否尝试将
{{projects}}置于视图中以检查projects是否已加载。? -
所有项目
-
哎呀,什么都没有显示
-
调试控制台我确实看到了:
在序列化“System.Data.Entity.DynamicProxies.Project_83750B92BCA5CE51EC420CEFFEAF12AA8B672E61DCC85D715490C55AF863FA22”类型的对象时检测到循环引用。 跨度> -
我添加了 this.Configuration.ProxyCreationEnabled = false;到我的实体上下文构造函数并且有效。不确定这是否有任何缺点?
标签: angularjs asp.net-mvc entity-framework-6