rlcrews
rlcrews

Reputation: 3562

how to load views into an MVC application when using angular

I have a project in which I am loading a view which contains an angular app. Within the angular app I have templates that I am trying to load. Within VS the directory structure shows

/views/reports/library.cshtml

within this directory I have added an html file/template

/views/reports/modal1.html

When I try to reference this html file either through angular or just through the address bar http://localhost/reports/modal1.html or http://localhost/views/reports/modal1.htmlI get a 404 error. It appears that angular is looking to the root of the website but I suspect the asp.net MVC routing is overriding something. I'd like to keep the files together for the app within the "view" directory vs. dumping them in the root. How do I go about loading the html templates within an MVC solution?

Upvotes: 0

Views: 310

Answers (1)

Wayne Ellery
Wayne Ellery

Reputation: 7958

There is a .webconfig in the views folder which prevents loading static files. Normally, you would not put the angular views in the mvc views. I would create a separate app directory at the root of the project:

/app
    /scripts
        /controllers
        /services
    /views

Another option is to allow for static files in the web.config in the views folder

<system.webServer>
  <handlers>
    <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>

Upvotes: 1

Related Questions