0

I'm using AngularJs in Asp.net Mvc5 for create single page application. I have a problem , when i use ng-repeat for show data in table , my data doesn't show in table but show empty rows

This is my Home Controller

angularFormsApp.controller("HomeController",
    function ($scope, $location, DataService) {
        DataService.getEmployees().then(
            function (results) {
                $scope.names = results.data;
            console.log(results.data);
            console.log("This is console");
            },
            function (error) {
                // on error
                alert("error read data" + error);
            }
        );
    });

This is my DataService

angularFormsApp.factory('DataService',
    function ($http) {

        var getEmployees = function () {

            return $http.get("Employee/GetEmployees");
        };
           return {
           
            getEmployees: getEmployees
        };
    });

This is My Html Page

<div ng-app="angularFormsApp">
  <div ng-controller="HomeController">
      {{ Namef }}

      <table class="table table-hover ">
          <thead>
              <tr>
                  <th>Name Employee</th>
                 <th>Note</th>
              </tr>
          </thead>
          <tbody>
              <tr ng-repeat="item in names">
                  <td>{{ item.FullName }}</td>
                  <td>{{ item.Note }}</td>
                  <td>
                      <a href="#!editor/{{ item.Id }}" class="btn btn-sm btn-info">Edite</a>
                      <a href="#" class="btn btn-sm btn-danger">Delete</a>
                  </td>
              </tr>
          </tbody>
      </table>
  </div>
</div>

This is My EmployeeController

public class EmployeeController : Controller
{
    // GET: Employee
    DataLayer.WebapplicationContext db = new DataLayer.WebapplicationContext();
    public ActionResult GetEmployees()
    {
        var data = db.Employees.ToList();   
        var camelCaseFormatter = new JsonSerializerSettings();
        camelCaseFormatter.ContractResolver = new CamelCasePropertyNamesContractResolver();
        var jsonResult = new ContentResult
        {
            Content = JsonConvert.SerializeObject(data, camelCaseFormatter),
            ContentType = "application/json"
        };
        return jsonResult;
        //return new HttpStatusCodeResult(404, "Our custom error message...");
    }

When i run this project i saw empty rows , it's above picture show my problem. Picture

And this is console log enter image description here

Mohammad Daliri
  • 1,370
  • 6
  • 20
  • 43

1 Answers1

0

I'm try this code and solve it my problem.In EmployeeController change ActionResult to JsonResult

 public JsonResult GetEmployees()
    {
          using (WebapplicationContext Obj = new WebapplicationContext())
        {
            List<Employee> Emp = Obj.Employees.ToList();
            return Json(Emp, JsonRequestBehavior.AllowGet);
        }
    }
Mohammad Daliri
  • 1,370
  • 6
  • 20
  • 43