AngularJS $http service not able to call asp.net mvc action
ASP.NET
1
Posts
1
Posters
2
Views
1
Watching
-
I am learning angularjs. i am using VS2013 and asp.net MVC 5. when user click a link then i am trying to call asp.net mvc action which return json but developer tool showing error called **Failed to load resource: the server responded with a status of 404 (Not Found) Home/GetCourses:1** this is my ASP.Net MVC action
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}public ActionResult Students() { return View(); } \[Route("Home/GetCourses")\] public JsonResult GetCourses() { //ViewBag.Message = "Your contact page."; string\[\] Courses = { "C#", "VB.Net", "SQL", "RDBMS" }; return new JsonResult { Data = Courses, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } }
This is my routing script of angularjs and $http call.
var app = angular.module("DemoApp", \["ngRoute"\]) .config(function ($routeProvider, $locationProvider) { $routeProvider .when('/', { // This is for reditect to another route redirectTo: function () { return '/home'; } }) .when("/home", { templateUrl: "Template/Home.html", controller: "homeController" }) .when("/course", { templateUrl: "Template/Course.html", controller: "courseController" }) .when("/students", { templateUrl: "Template/Students.html", controller: "studentController" }) //$locationProvider.html5Mode(false).hashPrefix('!'); // This is for Hashbang Mode $locationProvider.html5Mode(true) }) .controller("homeController", function($scope) { $scope.Message = "Home Page!!"; $scope.Title = "Home"; }) .controller("courseController", functi