I usually solve this using a factory like this -
First on the .cshtml page I load all angular js. Then create a factory for baseURL as follows:
function(angular){ var module = angular.module('NameOfMyModule'); //gt the module module.factory('BaseUrl', function(){ return '@Url.Action("Action", "Controller")'; }); }(window.angular);
Then enter BaseURL inside the controller -
.... module.controller('SomeController', [...., 'BaseUrl', function(...., BaseUrl){ $scope.baseUrl = BaseUrl; }]); ....`
Finally add it to the URL
$http.get($scope.baseUrl + /...../).then(....);
source share