Dona Dona - 7 months ago 15
AngularJS Question

Connection between AngularJS and Asp.Net MVC

I'm new using angular in MVC, I'm tring to read data from my controller make with ASP.NET MVC EF, to angular.
I'm try with this:

I added in my MVC Controller (the path is '/Controllers/BrandController.cs') this code:

public JsonResult GetBrands()
var result = db.Brands.ToList();
return Json(result, JsonRequestBehavior.AllowGet);

And then in the file js I put both service and controller of angular, that is the code:

var BrandApp = angular.module('BrandApp', []);

BrandApp.controller('BrandController', function ($scope, BrandService) {

function getBrands() {
.success(function (items) {
$scope.brands = items;
.error(function (error) {
$scope.status = 'Unable to load customer data: ' + error.message;


BrandApp.factory('BrandService', ['$http', function ($http) {

var BrandService = {};
BrandService.getBrands = function () {
return $http.get('/Home/GetBrands');
return BrandService;


What I'm wrong?

Thanks for you answers!!!

Win Win

Since the controller name is BrandController, URL should be /Brand/GetBrands.

BrandService.getBrands = function () {
   return $http.get('/Brand/GetBrands');

Normally, when you dealing with that kind of problem, you want to debug using Fiddler, Chrome Plugin PostMan, or some other tools.