WASIF WASIF - 4 months ago 43x
AngularJS Question

How to get data from db using angularjs and entity framework in mvc

I am newbie in learning AngularJS. Can anyone help me to understand how to get data from database using angularjs and entity-framework in mvc5.

Let's say we have data table named:

tbl_student {rollno, name}

and we want all the students data from the database. So what should be the most understandable way for new learners.


var myApp = angular.module("MyModule", []);
myApp.controller("DBcontroller", function ($scope, $http) {
.then(function (response) {
$scope.students = response.data

Html-code in file named "Test.cshtml"

<body ng-app="MyModule">
<table ng-controller="DBcontroller">
<tr ng-repeat="student in students">
<td>{{ student.Name }}</td>
<td>{{ student.City }}</td>
<td>{{ student.Institute }}</td>

In MVC Controller

public class AngularController : Controller
// GET: Angular
public ActionResult Test()
return View();

public JsonResult AllStudents()
using (EducationContext context = new EducationContext())
var students = context.tbl_Student.ToList();
return Json(students, JsonRequestBehavior.AllowGet);


The reason why this probably isn't working is because in your get you are adding the word Controller after Angular.

That is unnecessary.

This should work:

var myApp = angular.module('MyModule', []);
    myApp.controller('DBcontroller', function ($scope, $http) {
    $http.get('/Angular/AllStudents') // added an '/' along with deleting Controller portion
        .then(function (response) {
            $scope.students = response.data