public static IDisposable RenderWrapper(this HtmlHelper html, string name, object model = null) { var logger = ObjectFactory.GetInstance<Logger>(); if (html == null) { logger.Error("[HtmlHelpers].[RenderWrapperExtensions].[RenderWrapper] throwing exception ([html] == null)."); throw new ArgumentNullException("html"); } if (name == null) { logger.Error("[HtmlHelpers].[RenderWrapperExtensions].[RenderWrapper] throwing exception ([name] == null)."); throw new ArgumentNullException("name"); } var partial = html.Partial(name, model).ToHtmlString(); var parts = partial.Split(new [] { placeholderString }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length != 2) { logger.Error("[HtmlHelpers].[RenderWrapperExtensions].[RenderWrapper] throwing exception ([parts].[Length] != 2)."); throw new ArgumentException("Partial does not contains exactly one RenderWrapperPlaceholder.", "name"); } var onBeginData = new OnBeginData(html.ViewContext.HttpContext.Response, parts[0]); var onEndData = new OnEndData(html.ViewContext.HttpContext.Response, parts[1]); return new DisposableExtensionResult<OnBeginData, OnEndData> (BeginRenderWrapper, EndRenderWrapper, onBeginData, onEndData); }
// ending private static void EndRenderWrapper(OnEndData data) { data.Response.Write(data.ClosingPart); }