开发者

In ASP.NET MVC, why does the ViewContext have a Writer property?

开发者 https://www.devze.com 2023-01-22 21:08 出处:网络
Looking at the source, I see that a ViewContext is instantiated inside the ViewResultBase.ExecuteResult() method and is passed a writer.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消