0

I'm trying to route a simple view in ASP.NET AngularJs app but the view not loading on the browser ngView is commented out in browser.

JavaScript

(function () {

"use strict";

angular.module("app-trips", ["simpleControls", "ngRoute"])
    .config(function ($routeProvider) {

        $routeProvider.when("/", {
            $controller: "tripsController",
            $controllerAs: "vm",
            $templateUrl: "/views/tripsView.html"
        });

        $routeProvider.when("/editor", {
            $controller: "tripEditorController",
            $controllerAs: "vm",
            $templateUrl: "/views/tripEditorView.html"
        });

        $routeProvider.otherwise({ redirectTo : "/"});
    });

})();

CHTML

@model IEnumerable<App.Models.Trip>
@{
    ViewBag.Title = "Home"; 
}

@section Scripts{ 
    <script src="~/lib/angular/angular.min.js"></script>
    <script src="~/lib/angular-route/angular-route.min.js"></script>
    <script src="~/js/simpleControls.js"></script>
    <script src="~/js/app-trips.js"></script>
    <script src="~/js/tripsController.js"></script>
}

<div ng-app="app-trips">
    <div ng-view></div>
</

Results

Browser inspection

URL Bar

1 Answer 1

1

Remove $ sign from your $routeProvider route properties.

$routeProvider.when("/", {
    controller: "tripsController",
    controllerAs: "vm",
    templateUrl: "/views/tripsView.html"
});

Note: If you're using .NET MVC project, you can't access html files directly from views folder. I'd recommend to create a new folder and put static html files there.

Sign up to request clarification or add additional context in comments.

2 Comments

sorry to say it's not solving my problem. this is ASP.NET Core there is no web.config.
@RxNReza I guess same rules applies to asp net core, create a new static folder and place all html there.

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.