Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You might want to check <a href="https://stackoverflow.com/questions/3367106/pulling-a-view-from-a-database-rather-than-a-file">Pulling a View from a database rather than a file</a> or <a href="https://stackoverflow.com/questions/236972/using-virtualpathprovider-to-load-asp-net-mvc-views-from-dlls">Using VirtualPathProvider to load ASP.NET MVC views from DLLs</a></p> <p>Taking the code from my previous question on the subject.</p> <p>In your <code>FileExists()</code> method on the other page you replace the test code I have there with some db code that actually checks to see if the virtualPath has an entry in your database. Your database would look something like:</p> <pre><code>Views --tablename Path --view's virtual path SomeOtherValue </code></pre> <p>...and your call would then be something like</p> <pre><code>public class DbPathProvider : VirtualPathProvider { public DbPathProvider() : base() { } public override bool FileExists(string virtualPath) { Database db = new Database(); return db.Views.Any(w =&gt; w.Path == virtualPath); } public override VirtualFile GetFile(string virtualPath) { return new DbVirtualFile(virtualPath); } } </code></pre> <p>And now we modify the DbVirtualFile</p> <pre><code>public class DbVirtualFile : System.Web.Hosting.VirtualFile { public DbVirtualFile(string path) : base (path) { } public override System.IO.Stream Open() { Database db = new Database(); return new System.IO.MemoryStream( db.Views.Single(v =&gt; v.Path == this.VirtualPath)); } } </code></pre> <p>The virtualPath doesn't have to correspond to a real filesystem if you don't want it to. You can override the functionality by implementing these two classes.</p> <p>You can then register your new VirtualPathProvider in the global.asax like so</p> <pre><code>HostingEnvironment.RegisterVirtualPathProvider(new DbPathProvider()); </code></pre> <p>I hope this better answers your question.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload