當的方法(ReleaseView)被調用?
它由ViewResultBase.ExecuteResult
方法稱爲:
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
if (string.IsNullOrEmpty(this.ViewName))
{
this.ViewName = context.RouteData.GetRequiredString("action");
}
ViewEngineResult result = null;
if (this.View == null)
{
result = this.FindView(context);
this.View = result.View;
}
TextWriter output = context.HttpContext.Response.Output;
ViewContext viewContext = new ViewContext(context, this.View, this.ViewData, this.TempData, output);
this.View.Render(viewContext, output);
if (result != null)
{
result.ViewEngine.ReleaseView(context, this.View);
}
}
通知如何一旦視圖被呈現到輸出流中,ReleaseView方法被調用。所以基本上每次控制器操作返回一個View或PartialView時,當這個ActionResult完成執行時,它將調用底層視圖引擎的ReleaseView方法。
其他可以使用的地方在哪裏?
例如,如果您正在編寫自定義ActionResults。
那麼,我可以在我的控制器操作中使用這種方法嗎?
不,控制器操作在視圖引擎開始執行之前已經完成了很多操作。