Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. AngularJS $http service not able to call asp.net mvc action

AngularJS $http service not able to call asp.net mvc action

Scheduled Pinned Locked Moved ASP.NET
learningcsharpasp-netdatabasejavascript
1 Posts 1 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mou_kol
    wrote on last edited by
    #1

    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
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups