Skip to content

Instantly share code, notes, and snippets.

@johncoder
Created April 11, 2013 21:00
Show Gist options
  • Save johncoder/5367111 to your computer and use it in GitHub Desktop.
Save johncoder/5367111 to your computer and use it in GitHub Desktop.
public class StaticViewEngine : VirtualPathProviderViewEngine
{
public StaticViewEngine()
{
MasterLocationFormats = new string[] {
};
ViewLocationFormats = new[] {
"~/build/templates/{1}/{0}.html",
"~/build/templates/{0}.html",
"~/build/{1}/{0}.html",
"~/build/{0}.html",
"~/Views/{1}/{0}.html",
"~/Views/Shared/{0}.html"
};
PartialViewLocationFormats = ViewLocationFormats;
}
protected override IView CreatePartialView(ControllerContext controllerContext,
string partialPath) {
return new StaticView(partialPath);
}
protected override IView CreateView(ControllerContext controllerContext,
string viewPath,
string masterPath) {
return new StaticView(viewPath);
}
}
public class StaticView : IView
{
private string _viewPath;
public StaticView(string viewPath)
{
_viewPath = viewPath;
}
public void Render(ViewContext viewContext, System.IO.TextWriter writer)
{
viewContext.HttpContext.Response.WriteFile(_viewPath);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment