0

Please can someone tell me why the Views are not being inserted into the ng-view placeholder? I'm using the standard Visual Studio MVC project template with a HomeController and all my .cshtml files are in /Views/Home

I'm browsing to http://localhost:12345/Home/Example04#/view1

I see the Example04 header but not the contents of _View01.cshtml

Here is the rendered html:

<!DOCTYPE html>
<html ng-app="movieApp">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>Example04</title>
    <link href="/Content/site.css" rel="stylesheet"/>
    <script src="/Scripts/modernizr-2.5.3.js"></script>
</head>
<body>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>

<h2>Example04</h2>

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

<script>
    var movieApp = angular.module('movieApp', []);

    movieApp.config(function($routeProvider) {
        $routeProvider
            .when('/view1', {
                controller: 'MovieController',
                templateUrl: '_View1.cshtml'
            })
            .when('/view2', {
                controller: 'MovieController',
                templateUrl: '_View2.cshtml'
            })
            .otherwise({ redirectTo: 'view1' });
    });

    movieApp.controller('MovieController', function ($scope) {
        $scope.movieStars = [
            { name: 'Bruce Willis', character: 'John McClane' },
            { name: 'Sigourney Weaver', character: 'Ripley' },
            { name: 'Tom Cruise', character: 'Ethan Hunt' },
            { name: 'Harrison Ford', character: 'Indiana Jones' }
        ];
    });
</script>
    <script src="/Scripts/jquery-1.7.1.js"></script>
</body>
</html>
Bobbler
  • 633
  • 1
  • 7
  • 21
  • 1
    Have you checked your firebug request console, are you getting any 404 errors, the path of your views may be incorrect. – Chandermani Jul 24 '13 at 03:25
  • I can't believe I didn't think of that, thanks. Yes, got 404, requested URL is /Home/_View1.cshtml. So how do I make it request /Views/Home/_View1.cshtml ? – Bobbler Jul 24 '13 at 03:39
  • Try to access the view directly from browser. The url after `/home` is the url you want to provide. – Chandermani Jul 24 '13 at 05:31
  • I'm not sure what you mean, sorry. I can't access it directly and even if I could that wouldn't solve my problem. I've tried setting templateUrl to every variation of the path I can think of but I get 404s and 403s. – Bobbler Jul 24 '13 at 06:17
  • If I copy \Views\Home\_View1.cshtml to \Home\_View1.html (note the extension change) it works. I guess I should go through the rest of the tutorials and the answer will be there somewhere. Thanks. – Bobbler Jul 24 '13 at 06:25

0 Answers0