November Happy Hour will be moved to Thursday December 5th.

Previewing Blocks Error

Vote:
 

I am very new to Epi, and I am setting up our project from the ground up.  I have run into an issue where when I try and create a PreviewPage to be able to preview my block.  I have looked online at the various resources and I haven't uncovered any problems.  I copied the necessary files from the Alloy sample site into my project and it is having the following error.

[ObjectDisposedException: Cannot write to a closed TextWriter.]
   System.IO.__Error.WriterClosed() +53
   System.IO.StringWriter.Write(String value) +39
   EPiServer.Web.Mvc.Html.ContentAreaRenderer.RenderContentAreaItem(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem, String templateTag, String htmlTag, String cssClass) +837
   EPiServer.Web.Mvc.Html.ContentAreaRenderer.RenderContentAreaItems(HtmlHelper htmlHelper, IEnumerable`1 contentAreaItems) +119
   EPiServer.Web.Mvc.Html.ContentAreaRenderer.Render(HtmlHelper htmlHelper, ContentArea contentArea) +268
   EPiServer.Web.Mvc.Html.ContentAreaExtensions.RenderContentArea(HtmlHelper htmlHelper, ContentArea contentArea) +61
   ASP.util_views_shared_displaytemplates_contentarea_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in C:\Devspace\VSOnline\E-Commerce Website\Features\InitialDevelopment\CollectionsEtc.Site\Util\Views\Shared\DisplayTemplates\ContentArea.ascx:4
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +268
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +13
   System.Web.UI.Control.Render(HtmlTextWriter writer) +12
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +66
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +13
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29
   System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +41
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +66
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1303

#147948
Apr 28, 2016 15:03
Vote:
 

To add more information, it looks like the issue is around having multiple content areas defined in the preview block of the page.  If I use the following code, it works, but as soon as I uncomment the section, it throws the textwriter error.

<div class="row">
    <div class="span12">
        @Html.PropertyFor(m => m.PreviewBlock.ContentArea)
    </div>
</div>
 
@*
<div class="row">     <div class="span8">         @Html.PropertyFor(m => m.PreviewBlock.ContentArea)     </div> </div> <div class="row">     <div class="span4">         @Html.PropertyFor(m => m.PreviewBlock.ContentArea)     </div> </div>

*@
#147966
Apr 28, 2016 21:16
Vote:
 

How much have you copied from the PreviewController in Alloy?

Can you also explain the \Util\Views\Shared\DisplayTemplates\ContentArea.ascx more? What does the ascx look like? Why have you decided to have an .ascx instead of a razor .cshtml?

Technically there should be nothing wrong with mixing these but I would recommend sticking to one of either and .cshtml/Razor is basically standard when using MVC.

#148019
Apr 30, 2016 16:44
Vote:
 

I copied the preview controller exactly as is from the Alloy site.  We aren't using the .ascx control at all, so I'm not sure whre you noticed that.  Everything we are doing is in .cshtml. 

The 2nd post I made regarding the multpile content areas may be helpful since when I comment out the other content areas it works.  Which defeats the purpose of having a preview for block since I want ot see what it would look like at different break points.

#148020
Apr 30, 2016 17:01
Vote:
 

According to your callstack you seem to have something that has registered a ContentArea.cshtml.

ASP.util_views_shared_displaytemplates_contentarea_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in C:\Devspace\VSOnline\E-Commerce Website\Features\InitialDevelopment\CollectionsEtc.Site\Util\Views\Shared\DisplayTemplates\ContentArea.ascx:4

It seems to be located in the Utils/Views/Shared folder which also looks a bit wierd to me as views normally is put in the Views folder directly under your project root - not in a Utils folder.

Some clues to find this registration would be to look in your projects for TemplateModel, IRenderTemplate, RenderDescriptor.

#148022
Apr 30, 2016 17:08
Vote:
 

A coworker of mine was able to figure out the issue.  The ultimate issue was that he had some structure map code that was initializing things automatically instead of having to do it quasi-manually, and this code was causing the request to be issued multiple times, thus creating the error.  He removed the extra structure map code and the project started working again.

#148728
May 22, 2016 14:48
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.