4、View引擎介绍

View引擎介绍

Request =>Routing=>Controller=>ViewResult=>ViewEngine=>Response


配置Viewengine
对ViewEngine的配置写在Global.asax.cs

protected void Application_Start()
{
  ViewEngines.Engines.clear();
ViewEngines.Engines.Add(new MyViewEngine());
RegisterRoutes(RouteTable.Routes);
}

IViewEngine接口
public interface IViewEngine
{
ViewEnginesResult FindPartialView(ControllerContext controllerContext,string partialViewName,bool useCache);
ViewEnginesResult FindView(ControllerContext controllerContext,string masterName,bool useCache);
void ReleaseView(ControllerContext controllerContext,IView view);

}

IView接口
public interface IView
{
void Render(ViewCOntext viewContext,TextWriter write);
}

ViewContext 属性
HttpContext
Controller
RouteData
ViewData
TempData
View
clientValidationEnabled
FormContext
FormIdGenerator
IsChildAction
ParenActionViewContext
Write

选择一个ViewEngine
默认的WebFormViewEngine优势
很像WebForm
  使用masterpage
  支持C#
  使用System.Web.Ui.Page
  Vs2010自带智能感知

使用不同的ViewEngine
  使用不同的语言(ruby python)
希望得到更简单的Html(少用样式)
输出结果并非Html 比如:xaml,rss,pdf

Spark
  支持IronPython IronRuby
  简洁的输出
  支持类似MasterPage的技术

使用ViewEngine还是ActionResult

2011-4-15 23:20 danny

你可能感兴趣的:(Web,UI,python,webform,Ruby)