title: Angular JS factory in ASP.NET MVC 5
body: <p>Have a trouble with calling ASP.NET MVC Controller Action Methods from angular js factory.</p>
  
  <pre><code>var HomeModule = angular.module('HomeModule', []);
  
  HomeModule.controller('HomeController', function ($scope) {  
  
  });
  </code></pre>
  
  <p>This is my angular JS controller.</p>
  
  <pre><code>&lt;div ng-app="HomeModule" class="row"&gt;
  &lt;div ng-controller="HomeController" class="row"&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>
  Index.cshtml part of code looks like this.
  When I am trying to bind some $scope propetry from controller - is works. Please help me create factory like this to call my ASP.NET Controller Methods. All my solutions give's me errors in console.</p>
  
  <pre><code>someControllerApp.factory('someFactory', ['$http', function ($http) {
  
  var service = {
      GetSomeData: function () {
          return $http.post('/Some/SomeMethod');
      },
  };
  return service;
  }]);
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>angular.js:14324 TypeError: someFactory.GetSomeData(...).success is not a function
  at ChildScope.$scope.GetData (HomeController.js:7)
  at fn (eval at compile (angular.js:1), &lt;anonymous&gt;:4:141)
  at callback (angular.js:26673)
  at ChildScope.$eval (angular.js:17958)
  at ChildScope.$apply (angular.js:18058)
  at HTMLButtonElement.&lt;anonymous&gt; (angular.js:26678)
  at defaultHandlerWrapper (angular.js:3613)
  at HTMLButtonElement.eventHandler (angular.js:3601)
  </code></pre>
  
  <p>When Controller:</p>
  
  <pre><code>    var HomeModule = angular.module('HomeModule', []);
  
  HomeModule.controller('HomeController', function ($scope, someFactory) {  
  
      $scope.GetData = function () {
  
          someFactory.GetSomeData().success(function (data) {
              if (data.isSuccess) {
                  $scope.Address = data;
              } else {
                  window.location.assign("/Error/Error500");
              }
          });
      };
  
  });
  
  
  HomeModule.factory('someFactory', ['$http', function ($http) {
  
      var service = {
          GetSomeData: function () {
              return $http.post('/Home/GetUserData');
          }
      };
      return service;
      }]);
  </code></pre>