将.html文件呈现为ASP.NET MVC中的视图 [英] Rendering .html files as views in ASP.NET MVC

查看:144
本文介绍了将.html文件呈现为ASP.NET MVC中的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让.html文件与ASP.NET MVC项目中的其他.cshtml视图一起用作视图.这样做的主要原因是,在我的操作中,html文件要遵循其他视图遵守的相同自定义安全规则.

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 the same custom security rules in my actions that the other views abide by.

我不想使用.cshtml或.aspx扩展名,因为这样框架会尝试编译这些相当大的文件,这很浪费,因为这些文件没有任何要编译的东西.

I don't want to use the .cshtml or .aspx extensions because then the framework attempts to compile these rather large files which is waste since the files don't have anything to compile.

我已经更新了视图引擎以查找.html扩展名.这可以正常工作,但随后出现的错误是我没有注册的生成提供程序.我曾尝试在web.config中注册.html文件的生成提供程序,但这对错误没有任何影响.

I've updated the view engine to look for .html extensions. This works fine, but then the error I'm getting is that I don't have a registered build provider. I've tried registering a build provider for .html files in the web.config, but that doesn't make any difference in the error.

是否有一个生成提供程序将直接从.html文件中传递文本而无需尝试对其进行编译?

Is there a build provider that will just pass the text from the .html file straight through without attempting to compile it?

所以我要寻找的是将.html文件保存在views目录中,以便仅在通过操作请求时才呈现它们,并且.html视图不应通过任何编译运行.

So what I'm looking for is for .html files to live in the views directory so they are only rendered when requested through an action, and the .html views shouldn't be run through any compilation.

谢谢

克里斯

推荐答案

我找到了解决方案.在我的操作中,我返回FilePathResult,它只加载文件并通过它而不进行任何编译.

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");

这篇关于将.html文件呈现为ASP.NET MVC中的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆