Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Espen 4 posts 74 karma points
    Aug 18, 2015 @ 09:23
    Espen
    0

    Model does not get resolved when using SurfaceControllers

    Hi!

    I am using Ditto, and it works very well with my regular pagecontrollers. However, I stumbled into a problem when trying retrieve pages using a SurfaceController.

    I Have a code for retrieving Children by type, that looks something like this:

    public IEnumerable<T> GetChildren<T>(int pageId) where T : class
    {
        var page = new UmbracoHelper(UmbracoContext.Current).TypedContent(pageId);
        return page.Children.Where(x => x is T).As<T>().ToList();
    }
    

    With regular page controllers this function works very well. and I only get the children that is of the Type T.

    var children = GetChildren<CoursePage>(1073);
    

    When calling this function from a surfacecontroller, it does not recognize the pagetypes. None of the children is of Type T, and I get an empty list.

    The same thing happens when trying to get one page. I get the page, but it is not resolved as my model when using a SurfaceController.

    var page = new UmbracoHelper(UmbracoContext.Current).TypedContent(1073);
    

    I am pretty new with umbraco (and ditto), so maybe I am doing something completely wrong here..

    Does anyone have any idea of how to solve this?

    Thanks, Espen

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 20, 2015 @ 12:33
    Lee Kelleher
    0

    Hi Espen,

    Sorry, I don't completely follow what your set-up is.

    Are you using the DittoModelFactory? (or another model-factory?)

    I'm trying to understand where the CoursePage type comes into play.

    ... and just to check, is this Ditto v0.7.0?

    Thanks,
    - Lee

  • Espen 4 posts 74 karma points
    Aug 24, 2015 @ 08:19
    Espen
    0

    Hi!

    Yes, I am using the DittoModelFactory, and using Ditto 0.7.0.

    I'll try to explain a little easier:

    This is a regular PageController:

    public override ActionResult Index(RenderModel model)
    {
        if (model.Content is CoursePage)
        {
            //YES, This works. model.Content is of the type CoursePage
        }
    
        var page = new UmbracoHelper(UmbracoContext.Current).TypedContent(1074);
        if (page is CoursePage)
        {
            //This also works, because 1074 is a CoursePage
        }
    

    Everyting works!

    Now, if I try this in a SurfaceController, it does not work.

    I get the page, but it is not resolved as a CoursePage.

    public PartialViewResult Search()
    {
        var page = new UmbracoHelper(UmbracoContext.Current).TypedContent(1074);
        //This does not work in a surfaceController. page is not resolved as CoursePage
        if (page is CoursePage)
        {
    
        }
    

    Was this understandable ? I Get

    Thanks, Espen

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 24, 2015 @ 09:18
    Lee Kelleher
    0

    Hi Espen,

    Take a look the solution on this thread...

    https://our.umbraco.org/projects/developer-tools/ditto/ditto-feedback/65056-Ditto-As-returning-null-in-controller-called-through-an-Ajax-call

    It's worth a try.

    I'm not 100% convinced that this will fix your issue (with SurfaceControllers), as we add a patch for the culture issue in v0.7.0.

    Let me know if it works for you or not.

    Cheers,
    - Lee

  • Espen 4 posts 74 karma points
    Aug 24, 2015 @ 09:30
    Espen
    0

    Thanks!

    But I don't think this is the same problem. I have no issues with casting the page to a CoursePage. (So the culture issue is probably fixed :) )

    What i am trying to do is figure out if the page Actually is a CoursePage.

    Right now I have a ugly workaround, comparing the ContentType.Alias with the PublishedContentModel attribute. But this does of course not work with Interfaces etc..

    Espen

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Aug 24, 2015 @ 09:46
    Lee Kelleher
    0

    Hi Espen,

    Ah doh! I forgot about the model-factory setup, (it's Monday morning, I'm not fully awake yet) ;-)

    There must be some kind of Umbraco context missing (or not being set) when using a SurfaceController, (either a bug or intentional in the Umbraco core)?


    To be honest, I'm not 100% happy Ditto's model-factory implementation... I never use it myself - it was written as a prototype and released for if/when people wanted to contribute to it. So unfortunately I can't give much support for it :-(

    Depending on how comfortable you are with open-source stuff, please do feel free to grab the source-code and try debugging the DittoPublishedContentModelFactory.

    I'm totally happy to chat over it, (I just don't have a solution/fix for you)

    Cheers,
    - Lee

  • Espen 4 posts 74 karma points
    Aug 24, 2015 @ 11:01
    Espen
    0

    OK! Thanks!

    I'll do some digging to see if I can solve this...

Please Sign in or register to post replies

Write your reply to:

Draft