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();
}
[HttpGet]
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) {
debugger;
GetAllEmployee();
$scope.divEmployee = false;
function GetAllEmployee() {
debugger;
var getData = myservice.getAllEmployees();
getData.then(function (emp) {
$scope.employees = emp.data;
}),
function(){
alert('Error in getting data');
}
}
}); Angular service.js
pp.service("myservice", ["$http", function ($http) {
this.getAllEmployees = function () {
debugger;
var response = $http({
url: "/Home/GetAll",
method: "GET",
datatype:'JSON'
})
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
How to call the action method from angular service?
Aucun commentaire:
Enregistrer un commentaire