1

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.
thinkmmk
  • 487
  • 1
  • 8
  • 22
  • Yes you can. Read this http://stackoverflow.com/questions/4798334/is-it-possible-to-display-raw-html-from-database-in-asp-net-mvc-3 – Nipun Ambastha Jul 04 '13 at 13:38
  • 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 Jul 04 '13 at 15:56

1 Answers1

0

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.

Eilon
  • 25,582
  • 3
  • 84
  • 102
  • Thanks Elion, I understood what you said, I have edited my question. Please have a look at EDIT1 text above. – thinkmmk Jul 05 '13 at 04:40