0

I am developing a ASP.NET MVC - SPA website and I am using AngularJS. I have referred various articles given on the net. I am using ng-view, ngRoute and $routeProvider to achieve this but it is not working at all in my case. The code I have used for the routing is given below:

@{
    Layout = "~/Views/Shared/_LayoutPersonal.cshtml";
}
@{
    ViewBag.Title = "Index";
}

<h3>Questions</h3>
@*@Html.Action("Index","Question")*@
<div ng-app="overflowApp" ng-controller="overflowCtrl">
    <p><a href="#/">Main</a></p>

    <a href="#questions">Questions</a>
    <a href="#users">Users</a>
    <a href="#answers">Answers</a>
    <div ng-view></div>
</div>
    @section scripts{
        <script>
            function overflowController($scope, $http) {
                $scope.testList = ['a', 'b'];
            }

            var overflowApp = angular.module("overflowApp", ['ngSanitize', 'ngRoute']);
            overflowApp.controller("overflowCtrl", overflowController);
            overflowApp.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
                $routeProvider     
                    .when("/questions", {
                        templateUrl : "../Question"
                    })
                    .when("/users", {
                        templateUrl: "../Questions/users"
                    })
                    .when("/answers", {
                        templateUrl: "../Questions/answers"
                    });
            }]);
        </script>
    }

The URLs being displayed when I hover over the hyperlinks look like http://localhost:49910/#/questions and it doesn't load the view it is supposed to. Please help me out.

4
  • look at your network tab, what is the link being requested Commented Nov 14, 2016 at 6:40
  • Have checked this out: SO post? Commented Nov 14, 2016 at 7:15
  • @MihailStancescu: I have modified the code accordingly but no luck! Commented Nov 14, 2016 at 8:49
  • Try using the templateUrl: Questions, because that should be a request for ASP.NET MVC to handle to be able to return the compiled HTML from the Razor view. Commented Nov 14, 2016 at 9:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.