1

I'm new to Angular and I'm using Angular-UI-Router with ASP.NET MVC 4.

app.config(['$urlRouterProvider', '$stateProvider', function ($urlRouterProvider, $stateProvider) {
$urlRouterProvider.otherwise('/');

$stateProvider
    .state('about', {
        url: '/',
        template: 'HELLO WORLD'
    });
}]);

this works fine. HELLO WORLD is displaying so i know that everything is set up rather correctly.

but when i try templateUrl instead of template say:

app.config(['$urlRouterProvider', '$stateProvider', function ($urlRouterProvider, $stateProvider) {
$urlRouterProvider.otherwise('/');  //if you go to incorrect url it'll go back to home

$stateProvider
    .state('about', {
        url: '/',
        templateUrl: 'Home/About.html'
    });
}]);

nothing displays. I'm using almost a clean slate default template from scratch.. picking the "Internet Application" from default templates.. in my directories i have

Views --> Home --> About.html

I also have About.cshtml and I've tried that and it doesn't work neither. Help please!

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
user1189352
  • 3,628
  • 12
  • 50
  • 90

1 Answers1

2

ASP.NET MVC Views doesn't allow direct access to .html files of it. You need to allow the access from the web.config by adding handlers in system.webServer

Code

<system.webServer>
<handlers>
  <add name="JavaScriptHandler" path="*.js" verb="*"
     preCondition="integratedMode" type="System.Web.StaticFileHandler" />      
  <add name="HtmlScriptHandler" path="*.html" verb="*"
     preCondition="integratedMode" type="System.Web.StaticFileHandler" />
  <remove name="BlockViewHandler"/>
  <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>

Or the other way around would be you could create one new static folder other than Views that will have an html files in it. You could directly access the URL eg. static/about.html

For more details refer this Answer

Community
  • 1
  • 1
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299