MVC3和没有的VirtualPathProvider虚拟视图 [英] MVC3 and virtual view without VirtualPathProvider

查看:116
本文介绍了MVC3和没有的VirtualPathProvider虚拟视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC3应用程序,我有一些我保存在数据库中的字符串意见的内容。
现在,我需要创建一个虚拟视图,这返回给客户端。
我看,这可以通过的VirtualPathProvider完成。
但想知道这是否可以通过RazorViewEngine还是无法做到的。

I have a MVC3 Application and I have few of my views content saved in database as string. Now I need to create a virtual view and return this to the client. I read that this can be done by VirtualPathProvider. But wanted to know whether this can be done by RazorViewEngine or not.

EDIT1:
我已经使用了一个VPP在这个环节提出 http://blog.rocketbase.co.uk/2011/04/asp-net-mvc-virtual-path-provider/ 。我在Global.asax文件中注册它。
我有具有在物理上是美元的项目p $ psent太多意见pretty大网络应用。因此,在Global.asax中注册VPP后,我发现

I have used a VPP as suggested in this link http://blog.rocketbase.co.uk/2011/04/asp-net-mvc-virtual-path-provider/ . And I registered it in the global.asax file. I have a pretty big web app which has many views which are physically present in the project too. So after registering the VPP in global.asax I find that


  • 在Web应用程序的每个请求通过这个VPP去。无论是物理或动态视图。那么是不是有被击中这一个表现?并且不能我们通过跟踪URL控制这个调用VPP?

  • 我也有在我的项目只有.cshtml文件,但MVC试图查找的.ascx,的.aspx,.vbhtml等等等等文件。这再次我觉得会对性能产生负面影响。

推荐答案

RazorViewEngine 使用虚拟路径提供(VPP)来定位文件。在ASP.NET默认VPP位于磁盘上的文件。你可以写一个自定义的VPP,从数据库中获取的浏览内容。如果您在注册ASP.NET自定义VPP那么MVC就一定能够编译,加载和渲染这些看法。

The RazorViewEngine uses a virtual path provider (VPP) to locate files. The default VPP in ASP.NET locates files on disk. You can write a custom VPP that gets the view contents from a database. If you register the custom VPP in ASP.NET then MVC will certainly be able to compile, load, and render those views.

另一种方法是写一个全新的视图引擎 - 但是这绝非易事。如果你不希望使用VPP那么我认为你需要编写一个自定义视图引擎,因为两个内置的视图引擎肯定不支持此功能。

An alternative would be to write a completely new view engine - but that's no easy task. If you don't want to use a VPP then I think you'll need to write a custom view engine because the two built-in view engines certainly don't support this.

这篇关于MVC3和没有的VirtualPathProvider虚拟视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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