I am trying to extract the data from a table in my db using ajax and angular. Do a CRUD with MVC using asp.net and entity framework, the CRUD does not have any problem, but when displaying a data saved with angular no does not return anything I have consulted in different pages but still I do not get the result. I'm working on visual studio 2017
Script of the js
var conductores = angular.module('conductores', []);
conductores.controller('conductoresController', function ($scope, $http) {
$http.get('/Conductors/Index').then(function (response) {
$scope.lista = response.data;
})
})
Controller code
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using ajax_test;
namespace ajax_test.Controllers
{
public class ConductorsController : Controller
{
private Entities db = new Entities();
// GET: Conductors
public ActionResult Index()
{
return View(db.Conductor.ToList());
}
// Ajax
public ActionResult Listaconductores()
{
Entities db = new Entities();
var data = db.Conductor.ToList();
return Json(data, JsonRequestBehavior.AllowGet);
}
HTML code
@model IEnumerable<ajax_test.Conductor>
@{
ViewBag.Title = "Index";
}
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div ng-app="conductores" ng-controller="conductoresController"></div>
<div class="row">
<div class="col" s6>
<h2>Conductores</h2>
</div>
<table class="table">
<tr>
<th>
Nombre
</th>
<th>
Apellido
</th>
<th>
Direccion
</th>
<th>
Cedula
</th>
<th>
Telefono
</th>
</tr>
<tr ng-repeat="conductor in lista">
<td>
{{conductor.Nombre}}
</td>
<td>
{{conductor.Apellido}}
</td>
<td>
{{conductor.Direccion}}
</td>
<td>
{{conductor.Cedula}}
</td>
<td>
{{conductor.Telefono}}
</td>
</tr>
</table>
</div>
This is the result, of course, there is already data entered in the db