0

I have created an MVC application and added an Angularjs nuget. It was created HomeController and view for it. Home controlled isn't changed at all. My folder hierarchy:

enter image description here

Index.cshtml:

<!DOCTYPE html>
<html>

<head>
    <script src="~/Scripts/angular.js"></script>
    <script src="~/Scripts/angular-route.js"></script>
    <script src="~/Scripts/App/App.js"></script>

    <title>Title</title>
</head>

<body ng-app="sampleApp">

    <a href="#/route1">Route 1</a><br />
    <a href="#/route2">Route 2</a><br />

    <div ng-view></div>

    <script>
        var module = angular.module("sampleApp", ['ngRoute']);

        module.config(
            function ($routeProvider, $locationProvider) {
                $routeProvider.
                    when('/route1', {
                        templateUrl: 'Views/Home.html',
                        controller: 'RouteController'
                    }).
                    when('/route2', {
                        templateUrl: 'Views/Home.html',
                        controller: 'RouteController'
                    }).
                    otherwise({
                        redirectTo: '/'
                    });
            });

        module.controller("RouteController", function ($scope) {
            alert("I am here");
        })
    </script>
    </body>
</html>

Clicking on the links produces an 404 error http://localhost:50265/Home/Views/Home.html - this is link that was generated. I don't understand why there is Home inserted in link. And as the page of error said that it expected physical path

E:\SoftServe\IndividualTask\IndividualTask\Home\Views\Home.html

but i don't have Home folder in root folder E:\SoftServe\IndividualTask\IndividualTask I set the route to 'Views/Home.html' but not to 'Home/Views/Home.html'.

What is the base path for routing? How to make it work?

1
  • 1
    MVC doesn't allow to access files from view folder..you need to manipulate that thing by defining handler in web.config. Commented Sep 11, 2015 at 19:57

1 Answer 1

0

MVC doesn't allow to access files from view folder..you need to manipulate that thing by defining handler in web.config

Thank you. I have found this article: http://forums.asp.net/t/1689087.aspx?ASP+NET+MVC+Using+content+in+Views+folder and replace

<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />

on

<add name="BlockViewHandler" path="*.cshtml" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />

in web.config file that allows to get files from the View folder and doesn't allow only *.cshtml files from it.

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

Comments

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.