Rendering .html files as views in ASP.NET MVC

前端 未结 2 735
伪装坚强ぢ
伪装坚强ぢ 2020-12-30 11:47

I would like to have .html files serve as views alongside other .cshtml views in my ASP.NET MVC project. The main reason for this is so that the html files are subject to th

相关标签:
2条回答
  • 2020-12-30 12:23

    If you want to do it for one of your action method @Chris/ @Marius are awesome. as they given:

    return new FilePathResult("path_and_file.html", "text/html");
    //or better use
    return File("path_and_file.html", "text/html");
    

    I would like to add one more solution to the problem if you want to do it in web config to return pure html views from Views Folder:

    <!-- web.config under the Views folder -->
    
    <system.webserver>
    <handlers>
    
    <add name="HtmlScriptHandler" path="*.html" verb="*" precondition="integratedMode"
         type="System.Web.StaticFileHandler" />
    </handlers>
    </system.webserver>
    

    Here is a post suggesting it.

    0 讨论(0)
  • 2020-12-30 12:31

    I found a solution. In my action I return FilePathResult and it just loads the file and passes it through without any compilation.

    return new FilePathResult("path_and_file.html", "text/html");
    
    0 讨论(0)
提交回复
热议问题