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

Render page in Content Area MVC

Vote:
 

Hi,

 

I'm trying to figure out how to create a second MVC template renderer (controller ?) to handle rendering a Page when added to a ContentArea. With Page

[ContentType(DisplayName = "VenuePage", GUID = "b27f0476-dcb5-474a-9f70-a1fcfc9fc772", Description = "")]
    public class MyPage : PageData
    {
        /*
                [CultureSpecific]
                [Editable(true)]
                [Display(
                    Name = "Main body",
                    Description = "The main body will be shown in the main content area of the page, using the XHTML-editor you can insert for example text, images and tables.",
                    GroupName = SystemTabNames.Content,
                    Order = 1)]
                public virtual XhtmlString MainBody { get; set; }
         */
    }

Default Template Renderer (Controller)
    [TemplateDescriptor(Default=true)]
    public class MyPageController : PageController<MyPage>
    {
        public ActionResult Index(MyPage currentPage)
        {
            /* Implementation of action. You can create your own view model class that you pass to the view or
             * you can pass the page type for simpler templates */

            return View(currentPage);
        }
    }
    
Now I have created a second Template Renderer when the context has a "Teaser" Tag

    [TemplateDescriptor(Tags=new string[]{"Teaser"})]
    public partial class MyPageController_Teaser : PartialContentController<MyPage> //PartialContentController<MyPage> // PageController<MyPage>
    {
        public override ActionResult Index(MyPage currentContent)
        {
            return base.Index(currentContent);
        }
        //public ActionResult Index(MyPage currentPage)
        //{
        //    /* Implementation of action. You can create your own view model class that you pass to the view or
        //     * you can pass the page type for simpler templates */

        //    return View(currentPage);
        //}
    }
    
As you can see I've been trying derriving from PartialContentController<T> and the normal PageController<T> but this template renderer is never called.

Instead I get

Server Error in '/' Application.


The controller for path '/' was not found or does not implement IController.

 

My HomePage which contains the ContentArea property MyPageTeasers has the following markup in its View

@Html.PropertyFor(m => m.MyPageTeasers, new { Tag = "Teaser" })

 


As far as I understood this was all that should be required to have the second template renderer (controller) be used when the ContentArea is rendered and the Tag "Teaser" is set in the rendering context ?

Has anyone managed to do this in MVC ?

#72580
Jun 21, 2013 16:32
Vote:
 

I think you might find the answer in this thread: http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=60495 there is also a blogpost about this by johan björnfot:

http://world.episerver.com/Blogs/Johan-Bjornfot/Dates1/2012/9/EPiServer-7--Rendering-of-content/

 

#72582
Jun 22, 2013 11:33
Vote:
 

Thanks Eric,

 

I figured those posts was out of date since they were using the RenderDescriptor rather that its replacement TemplateDescriptor ?

Either way I tried following the post:

http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=60495

but with the RenderDescriptor replaced with TemplateDescriptor but to no avail. I still get the same error, "the controller for path "/" was not found or does not implement IController.

 

I have read the TemplateResolver algorithm etc and as far as I can see it should work with what I have done.

* I have a controller set to render a page type when a specific tag is set in the rendering context.

* I set this tag in the rendering of the ContentArea with @Html.PropertyFor(m=>m.MyPageTeasers, new { Tag = "Teaser" } )

 

Surely it should be the same principle as how the DisplayChannels work ?

* Create another Controller to render the content when tag named according to your Display Channel is set.

* Set the Display Channel in Edit mode.

 

#72726
Jun 27, 2013 10:38
Vote:
 

FYI,

It looks like my biggest mistake was not following the MVC convention of suffixing all controllers with 'Controller'

So stripped back to basics all you do need is a PageController<T> set to render page type T when specific tag is set.

**Note however that I did need to add the TemplateTypeCategory=EPiServer.Framework.Web.TemplateTypeCategories.MvcPartialController

**Note controller name now ends with 'Controller'

 

So my controller now looks like :

[TemplateDescriptor(Tags=new string[]{"Teaser"}, TemplateTypeCategory=EPiServer.Framework.Web.TemplateTypeCategories.MvcPartialController)]
public class MyPageController_TeaserController : PageController<MyPage>
{
    public ActionResult Index(MyPage currentPage)
    {
        return View(currentPage);
    }
}

    

 

#72743
Jun 27, 2013 12:19
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.