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

Render children with thier own view?

Vote:
 

Hi,

this is my first EPi7 MVC project, so I'm not sure if this question is stupid or not.. :)

I have a page with a few children. The children of the page is of various page types.

 

Is there a way to render the children with their own view on this page?

#64963
Jan 17, 2013 1:11
Vote:
 

Interesting requirement, let's see if someone would be able to come up with a solution :)

#64973
Jan 17, 2013 4:21
Vote:
 

Hi, I am not sure what you want to achieve - how would you want your view to look like? Like some listing page that lists an image, heading and some intro text? Perhaps you can inherit from the same interface in all pages and map the interface to view model. Than you can use the same block to render the list of view models. Something like this:

        @foreach (var teaser in @Model.Teasers)
        {
            Html.RenderPartial("Blocks/Teaser", @teaser);
        }

Sorry if this is not what you had in mind, perhaps you can give some more info? 

 

 

#64985
Jan 17, 2013 9:35
Vote:
 

Hey Erik,

You can iterate over them and render them using Html.RenderContentData(child, false).

RenderContentData will then render them using the same template resolving mechanism as for content areas, meaning you could have a partial view for each type in shared.

#64988
Edited, Jan 17, 2013 9:53
Vote:
 

Hi and thanks for the answers!

Didn't get any notifications so I digged up my own solution that ended up like this:

@foreach (var child in EPiServer.DataFactory.Instance.GetChildren(Model.ContentLink.ToPageReference()))
        {
            Html.RenderPartial(String.Format("~/Views/{0}/Index.cshtml", child.GetType().Name.Replace("Page", "")), child, ViewData);
        }

    

I tried the RenderContentData first, but it never worked, guess I put my views in the wrong place, gonna give it another try!

#65004
Jan 17, 2013 12:20
Vote:
 

I tried Joels approach again, and it worked. Supposed that it was an easy task if you only knew how. :)

#65006
Jan 17, 2013 12:48
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.