0

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?

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

4 Comments

the challenge I have is this is not a new project but a phased implementation where I am cutting in SPA's into a hybrid webform/MVC application. It's pretty large to where I would like to keep files together vs. introducing new directories.I'll try the static files approach this looks like it may be the approach to take for this solution.
I can't see a problem with adding another directory for the angular app inside your legacy application. Technically the Views folder is meant for mvc views and that is all
so you propose to create a new directory from the root and add the templates there for the MVC view?
I would normally create an app directory from the root which would be used for the angular app and everything for the app would be nested inside it. I updated my answer as the formatting wasn't the best

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.