Restore the TextWriter to ViewContext
This commit is contained in:
parent
8ea196023e
commit
6610788b75
|
|
@ -36,7 +36,9 @@ namespace Microsoft.AspNet.Mvc
|
|||
var viewContext = new ViewContext(_serviceProvider, context.HttpContext, context.RouteValues, ViewData)
|
||||
{
|
||||
Url = new UrlHelper(context.HttpContext, context.Router, context.RouteValues),
|
||||
Writer = writer,
|
||||
};
|
||||
|
||||
await view.RenderAsync(viewContext, writer);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,20 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
using (var bodyWriter = new StringWriter(contentBuilder))
|
||||
{
|
||||
Output = bodyWriter;
|
||||
await ExecuteAsync();
|
||||
|
||||
// The writer for the body is passed through the ViewContext, allowing things like HtmlHelpers
|
||||
// and ViewComponents to reference it.
|
||||
var oldWriter = context.Writer;
|
||||
context.Writer = bodyWriter;
|
||||
|
||||
try
|
||||
{
|
||||
await ExecuteAsync();
|
||||
}
|
||||
finally
|
||||
{
|
||||
context.Writer = oldWriter;
|
||||
}
|
||||
}
|
||||
|
||||
var bodyContent = contentBuilder.ToString();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.AspNet.Abstractions;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Rendering
|
||||
|
|
@ -23,5 +24,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
public ViewData ViewData { get; private set; }
|
||||
|
||||
public IDictionary<string, object> ViewEngineContext { get; private set; }
|
||||
|
||||
public TextWriter Writer { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue