1
votes

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: 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

  • every request in the web app goes via this VPP. Be it for physical or dynamic view. So isn't there be a performance hit for this? And cant we control this call to the VPP by tracking the URL?
  • Also I have only .cshtml files in my project, but mvc tries to find .ascx, .aspx, .vbhtml etc etc files. Which again I feel will have a negative impact on the performance.
1
No, that will just put some formatted html on the client. But I was looking for some way which will have allow me to send complete virtual view. - thinkmmk

1 Answers

0
votes

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.

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.