Looking at the source, I see that a ViewContext is instantiated inside the ViewResultBase.ExecuteResult() method and is passed a writer.
ViewContext viewContext = ne开发者_运维知识库w ViewContext(context, this.View, this.ViewData, this.TempData, output);
But when the view is rendered the writer is passed into the View.Render() method and I believe that is on purpose, so that view engines other than the WebForms view engine can render into that writer.
this.View.Render(viewContext, output);
So what is the purpose of the writer that's part of the ViewContext?
So you can grab the output of a view and do whatever you need with it. A good example is using the viewengine to render HTML templated emails.
精彩评论