Try our conversational search powered by Generative AI!

Problem rendering "container" page programmatically

Vote:
 

When I create a "container" page (a page without a template) from admin mode, the icon looks as it is supposed to and this page is not rendered as expected (There is no preview for this page is displayed while edit mode loads).

However, when I create it programmatically, the PreviewBlockController gets called and I get the grey view instead of no view. 

I cannot use BlockData instead of IContentData here (getting the exception):

public class PreviewBlockController : ActionControllerBase, IRenderTemplate<IContentData>

=>

public class PreviewBlockController : ActionControllerBase, IRenderTemplate<BlockData> (this gives an error, as the preview expects a PageData).

Is it possible to use preview page for blocks only and not as default controller?

This is the view:

@using EPiServer.Web.Mvc.Html
@inherits System.Web.Mvc.WebViewPage<EPiServer.Core.IContentData>

@{
    Layout = null;
}

@if(@Model != null) {
    { Html.RenderContentData(@Model, false); }
}

    

This is the controller:

    [TemplateDescriptor(Inherited = true, Tags = new string[] { RenderingTags.Preview })]
    public class PreviewBlockController : ActionControllerBase, IRenderTemplate<IContentData>
    {
        public ActionResult Index()
        {
            var contentLink = Request.RequestContext.GetContentLink();
            IContentData content = null;
            if (contentLink != null)
            {
                var contentRepo = ServiceLocator.Current.GetInstance<IContentRepository>();
                content = contentRepo.Get<IContentData>(contentLink);

                if (!(content is SiteBlockData)) return null;
            }

            return View(content);
        }
    }

    

#64774
Jan 09, 2013 16:22
Vote:
 

I have just realized that my first sentence might be misunderstood. So, if I create a container page from admin mode, everything behaves as it is supposed to.

When I create a "container" page (a page without a template) from admin mode, the icon looks as it is supposed to and this page is not rendered as expected (There is no preview for this page is displayed while edit mode loads).

 =>

When I create a "container" page (a page without a template) from admin mode, the icon looks as it is supposed to and this page is not rendered. This is expected (There is no preview for this page is displayed while edit mode loads).

 
#64775
Jan 09, 2013 16:23
Vote:
 

Hi Marija,

The trick is to let your preview controller implement IRenderTemplate<BlockData> AND in the TemplateDescriptor attribute specify TemplateTypeCategory as TemplateTypeCategories.Page.

If you use something more general than BlockData the controller will be a preview for pages as well, but if you specify BlockData the controller will be registered as a partial renderer. Therefor you need to "force" it to be registered as a "full page" renderer.

#64777
Jan 09, 2013 17:27
Vote:
 

Hi, Joel,

Thx a lot for your answer!

I am using MVC, so instead of TemplateTypeCategories.Page, this one works for me  TemplateTypeCategories.MvcController.

#64792
Jan 10, 2013 11:09
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.