title: ASP.NET MVC 3.0 Razor, load View from anywhere out of the box?
body: <p>Is it true that it is possible to load View from anywhere without
  implementation of custom <code>VirtualPathProvider</code> in MVC 3.0? </p>
  
  <p>If it is true how to do it? </p>
  
  <p>Basically it is not a problem to implement custom <code>VirtualPathProvider</code> which would load the 
  View from anywhere but my implementation working only in MVC 2.0 and not working wih MVC 3.0, fore some reason method <code>GetFile</code> newer called for not existed views in MVC 3.0 and in that case I am getting "<code>Server Error in '/' Application.</code>" </p>
  
  <p>I followed the same code for my custom <code>VirtualPathProvider</code> from here: <a href="http://buildstarted.com/2010/09/28/mvc-3-razor-view-engine-without-a-controller/" rel="noreferrer">http://buildstarted.com/2010/09/28/mvc-3-razor-view-engine-without-a-controller/</a></p>
  
  <p>UPDATE 1</p>
  
  <p>OK i did fix my problem with my custom <code>VirtualPathProvider</code> after i put registration of my custom <code>VirtualPathProvider</code> provider first line in the Application_Start()   </p>
  
  <pre><code>    protected void Application_Start()
      {
          //Should be first line before routes and areas registration.
          HostingEnvironment.RegisterVirtualPathProvider(new MyVirtualPathProvider());
  
          AreaRegistration.RegisterAllAreas();
  
          RegisterGlobalFilters(GlobalFilters.Filters);
          RegisterRoutes(RouteTable.Routes);
      }
  </code></pre>
  
  <p>When registration of custom VirtualPathProvider in <code>Global.asax.cs</code> folowing after <code>AreaRegistration.RegisterAllAreas();</code> or <code>RegisterRoutes(RouteTable.Routes);</code> method method <code>override VirtualFile GetFile(string virtualPath)</code> wont work for "virtual Views".</p>
  
  <p>UPDATE 2</p>
  
  <p>does it means that the classes <code>RazorView</code> and <code>RazorViewEngineRender</code> is the answer?</p>
  
  <p>UPDATE 3</p>
  
  <p>If i have string representation of my razor view which does not exists in the file system (e.g i store razor views in database) how may i render it using this kind of approach <a href="http://buildstarted.com/2010/09/28/mvc-3-razor-view-engine-without-a-controller/" rel="noreferrer">http://buildstarted.com/2010/09/28/mvc-3-razor-view-engine-without-a-controller/</a></p>
  
  <p>For example string representation of my View looks like this:</p>
  
  <pre><code>"@{
      ViewBag.Title = ""About Us"";
  }
  
  &lt;h2&gt;About&lt;/h2&gt;
  &lt;p&gt;
       Put content here.
  &lt;/p&gt;"
  </code></pre>
  
  <p>UPDATE 4</p>
  
  <p>Now i see, to be able to use <code>@Html.&lt;something&gt;</code> custom TemplateBase should be implemented.
  The sample of implementation of <code>HtmlTemplateBase&lt;T&gt;</code> could be fount here <a href="http://www.fidelitydesign.net/?p=239" rel="noreferrer">http://www.fidelitydesign.net/?p=239</a>, but it won't work with RazorEngine v2, i am successfully getting template compiled, then after assembly loaded method <code>public override void Execute()</code> won't be executed i am getting an error: The method or operation is not implemented (stacktrace: <a href="http://tinypic.com/r/dcow4/7" rel="noreferrer">http://tinypic.com/r/dcow4/7</a>)</p>
  
  <p>To make “public override T Model” happened i did change declaration of “public TModel Model” to “public virtual TModel Model” in “public abstract class TemplateBase : TemplateBase, ITemplate”. May be there is some another changes should be done? Or something in <code>HtmlTemplateBase&lt;T&gt;</code> should be done another way?</p>