使用mvc中的angularjs从主键和外键关系表中获取数据

时间:2017-04-06 12:26:54

标签: angularjs asp.net-mvc

我有3个表CollectionSubcollectionProducts

Collection表ID在SubcollectionProducts表中用作forgien键。 Sub .... table id用​​作Products表中的外键。

现在我正在尝试使用角度js从Collection获取集合列表。但是我没有在视图中得到任何东西。在控制台中错误显示。当我点击错误时,它会转到错误:

  

ngRepeat:愚弄
  中继器中的重复键。

但是当我尝试获取另一个表的数据时,它没有任何关系,所以我想知道如何从表中获取与另一个表与外键的关系。我也在$index尝试追踪,但那不起作用



  public JsonResult getcolldata()
       {
           var lst = eShoppingEntitiesContetxt.Collections.Where(x => x.IsActive  == true).ToList();
           var data = JsonConvert.SerializeObject(lst, new JsonSerializerSettings
           {
               ReferenceLoopHandling = ReferenceLoopHandling.Ignore
           });
           return Json(data, JsonRequestBehavior.AllowGet);
       }






<!-- AppModule -->
var app = angular.module("StudentApp", []);

<!-- Service -->
app.service("EmployeeService", function ($http) {
    this.getEmployee = function () {
       
        return $http.get("/User/getcolldata");
    };
});

<!-- Controller -->
app.controller("StudentController", function ($scope, EmployeeService) {
  
    GetAllEmployee();

    function GetAllEmployee() {       
        $scope.name = "Sample";
     
        var getAllEmployee = EmployeeService.getEmployee();
        getAllEmployee.then(function (emp) {                    
           $scope.employees = emp.data;          
        }, function () {
            alert('Data not found');
        });
    }
});
&#13;
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="~/Scripts/AppModule.js"></script>
<script src="~/Scripts/Controller.js"></script>
<script src="~/Scripts/Services.js"></script>

<div ng-app="StudentApp" class="container">
    <br/>
    <br/>
    <input type="text" placeholder="Search Student" ng-model="searchStudent" />
    <br />
    <div ng-controller="StudentController">

        <table class="table">
            <tr ng-repeat="r in employees | filter : searchStudent" >
                <td>{{ r.Col_Title }}</td>              
                
            </tr>
        </table>
    </div>
</div>
&#13;
&#13;
&#13;

This is my collection table This is error

0 个答案:

没有答案