ASP.NET MVC ViewEngine

The first purpose of ZPT-Sharp is to serve as an ASP.NET MVC ViewEngine.

The minimum to get started

To get started using ZPT-Sharp, all you need do is to register the view engine, and you are away!

// Typically in your Global.asax.cs:
protected void Application_Start()
{
  ViewEngines.Engines.Clear();
  ViewEngines.Engines.Add(new ZptViewEngine());
}

You may now create and use ZPT views in your application by including the files (in an acceptable format, either .pt or .xml) in the Views directory. There is no special requirement upon your controllers or your models.

Supplemental TALES variables

When writing MVC views using ZPT, a number of additional TALES root variables are available, provided by the ZPT-Sharp MVC ViewEngine. Their values are populated automatically based upon the ViewContext provided by MVC.

Name Description MVC equivalent
ViewData The view-data dictionary ViewContext.ViewData
TempData The temp-data dictionary ViewContext.TempData
ViewBag The view-bag dynamic object ViewContext.ViewBag
FormContext The form context object ViewContext.FormContext
Application The application state dictionary ViewContext.HttpContext.Application
Cache The cache dictionary ViewContext.HttpContext.Cache
Request The request helper ViewContext.HttpContext.Request
Response The response helper ViewContext.HttpContext.Response
RouteData The route-data ViewContext.RouteData
Server The ASP.NET server helper ViewContext.HttpContext.Server
Session The ASP.NET session helper ViewContext.HttpContext.Session
Model The MVC model (you may also use here) ViewContext.ViewData.Model
Views Filesystem directory object pointing at the virtual path ~/Views/ None