ASP.NET + AngularJS错误500尝试访问GET方法

时间:2018-10-08 19:43:45

标签: asp.net angularjs asp.net-mvc

下午好!

我正在按照本教程https://ramanisandeep.wordpress.com/2017/07/09/angularjs-crud-using-asp-net-mvc5-vs-2015-project-setup-and-read-employee-data/构建CRUD,但遇到了一些困难。

我试图发出GET请求以显示数据库中的列表,但标题中出现错误。

这是我的UserController

 public JsonResult GetEmployee()
    {
        using (CadDBEntities db = new CadDBEntities())
        {
            List<User> empList = db.User.ToList();
            return Json(empList, JsonRequestBehavior.AllowGet);
        }
    }

通过连接数据一切正常。

这是我的Module.js

var myapp;
 (function () {
      myapp = angular.module('my-employees', []);
})();

这是我的Service.js

myapp.service('employeeService', function ($http) {
this.getAllEmployees = function () {
    return $http.get("/User/GetEmployee");
   }
});

这是我的Controller.js

myapp.controller('employee-controller', function ($scope, employeeService) {

//Loads all Employee records when page loads
loadEmployees();

function loadEmployees() {
    var employeeRecords = employeeService.getAllEmployees();
    employeeRecords.then(function (d) {    
        $scope.Users = d.data;
    },
    function () {
        alert("Error occured while fetching users list...");
    });
}
)};

这是cshtml

    div class="container" ng-controller="employee-controller">
    <div >
        @*<div class="panel-heading">
            Employee Details - Grid CRUD operations
        </div>*@

        @*Add New button*@
        <div>
            <button type="button" style="margin-top: 20px; margin-bottom: 20px;" class="btn btn-info"
                    data-target="#AddNew" data-toggle="modal" id="btnAddEmployee">
                Add Employee
            </button>
            <br />
        </div>

        @*Employee Records*@
        <table class="table table-bordered">
            <thead style="background-color:lightblue;">
                <tr>
                    <th>Nome</th>
                    <th>Data de Nascimento</th>
                    <th>CPF</th>
                </tr>
            </thead>
            <tbody>
                <tr ng-repeat="emp in Users">
                    <td> {{emp.username}}</td>
                    <td> {{emp.birthdate}}</td>
                    <td>{{emp.cpf}}</td>
                    <td style="width:200px;">
                        <a href="#" class="btn btn-info">Update</a>
                        <a href="#" class="btn btn-danger">Delete</a>
                    </td>
                </tr>
            </tbody>
        </table>
        </div>
    </div>
</div>

这些是我得到的错误

enter image description here

enter image description here

我在代码中做错什么了吗?我正在尝试两天没有成功

0 个答案:

没有答案