lundi 13 février 2017

How to call the action method from angular service?

Vote count: 0

I'm trying to call the mvc controller in angular service.js file.

     public class HomeController : Controller
        public ActionResult Index()
            return View();
        public JsonResult GetAll()
            using (EmployeeEntities datacontext = new EmployeeEntities())
                var employeelist = datacontext.Employees.ToList();
                return Json(employeelist, JsonRequestBehavior.AllowGet);

} }

Angular controller:

app.controller("mycontroller", function ($scope, myservice) {
$scope.divEmployee = false;

function GetAllEmployee() {

    var getData = myservice.getAllEmployees();
    getData.then(function (emp) {
        $scope.employees =;
        alert('Error in getting data');

}); Angular service.js

pp.service("myservice", ["$http", function ($http) {
this.getAllEmployees = function () {
    var response = $http({
        url: "/Home/GetAll",
        method: "GET",

        return response;

So when i trying run call the Url, the "Home/GetAll" is not found error is coming. So how to call the url in service.

asked 49 secs ago

Let's block ads! (Why?)

How to call the action method from angular service?

Aucun commentaire:

Enregistrer un commentaire