diff --git a/src/Orchard/Mvc/ViewPage.cs b/src/Orchard/Mvc/ViewPage.cs index 9ed73ffbc..a0c41d652 100644 --- a/src/Orchard/Mvc/ViewPage.cs +++ b/src/Orchard/Mvc/ViewPage.cs @@ -2,6 +2,7 @@ using System.IO; using System.Web; using System.Web.Mvc; +using System.Web.UI; using Autofac; using Orchard.DisplayManagement; using Orchard.Localization; @@ -50,11 +51,29 @@ namespace Orchard.Mvc { } public IDisposable Capture(Action callback) { - throw new NotImplementedException(); + return new ViewContextSubstitution(Writer, callback); } } + public class ViewContextSubstitution : IDisposable { + private readonly HtmlTextWriter _context; + private readonly Action _callback; + private readonly TextWriter _oldWriter; + private readonly TextWriter _writer; + + public ViewContextSubstitution(HtmlTextWriter context, Action callback) { + _context = context; + _oldWriter = _context.InnerWriter; + _callback = callback; + _context.InnerWriter = _writer = new StringWriter(); + } + + public void Dispose() { + _callback(new HtmlString(_writer.ToString())); + _context.InnerWriter = _oldWriter; + } + } public class ViewPage : ViewPage { } } \ No newline at end of file diff --git a/src/Orchard/Mvc/ViewUserControl.cs b/src/Orchard/Mvc/ViewUserControl.cs index 13b386d2b..69ff8792d 100644 --- a/src/Orchard/Mvc/ViewUserControl.cs +++ b/src/Orchard/Mvc/ViewUserControl.cs @@ -53,7 +53,7 @@ namespace Orchard.Mvc { } public IDisposable Capture(Action callback) { - throw new NotImplementedException(); + return new ViewContextSubstitution(Writer, callback); } }