Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Page Partial Renderer with a Controller/ViewModel

Vote:
 

Hi

For the site I am currently working, we ant to give the user the ability to drag and drop pages from the menu structure into a dropzone and render a link to that page, and all of the children for that page underneath it. As I need to do a bit of logic to get the children, I want to be able to create a ViewModel for that partial view to get the data, rather than messing up my view with it. In order to do this Im preetty confident I will need its own controller.

I am having some problems getting it working though, I have used a similar approach to this for adding custom renderer's for blocks before so I was hopeful this would work but so far no luck. I have a controller as the folliowing:

[TemplateDescriptor(AvailableWithoutTag = false, Tags = new string[] { Global.ContentAreaTags.FooterNavigation })]
    public class FooterMenuPagePartialController : DefaultPageController
    {
        public ActionResult Index(SitePageData currentPage)
        {
            var model = new FooterMenuViewModel(currentPage);

            return this.View("PagePartials/FooterMenu", model);
        }
    }

    

My ViewModel (still needs some logic):

public class FooterMenuViewModel
    {
        public SitePageData Page { get; set; }
        public List<SitePageData> Children { get; set; } 

        public FooterMenuViewModel(SitePageData page)
        {
            this.Page = page;
        }
    }

    

Then at the moment my very simple view:

@model FooterMenuViewModel

@Model.Page.PageName

    

The error I am being thrown is:

System.InvalidOperationException: The model item passed into the dictionary is of type 'Castle.Proxies.StartPageProxy', but this dictionary requires a model item of type 'EPiServer.Templates.Logicalis.Models.ViewModels.FooterMenuViewModel'.

Can anyone suggest where I may be going wrong or if there is an alternate approach?

Many thanks in advance!!!!
Dave

#73823
Aug 12, 2013 10:30
Vote:
 

You're using the ViewTemplateModelRegistrator to hook up the page partials, correct?

I understand what you are trying to do, and it logically makes sense, but I can't think of a way to do this using a page partial, unless you put the logic to get the children directly in the Razor view.

I think the alternate approach is to make a block with a PageReference property, but I'm sure you already are aware of this approach.

I've love to see if anyone can provide a solution to this...

#73842
Aug 12, 2013 19:30
Vote:
 
#73855
Aug 13, 2013 7:43
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.