Copied to clipboard

Flag this post as spam?

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


  • Gareth Wright 32 posts 101 karma points c-trib
    Nov 22, 2016 @ 11:49
    Gareth Wright
    0

    DittoPublishedContentModelFactory Method not found error

    Hi all,

    I've put a very simple sandbox together and I've used the latest versions of Ditto (0.10.0), Ditto.ModelFactory (0.1.1) and Umbraco (7.5.4).

    I want my models to auto bind on startup, so I'm using the following code:

     public class EventHandlers : ApplicationEventHandler
    {
        protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            var types = PluginManager.Current.ResolveTypes<PublishedContentModel>();
            var factory = new DittoPublishedContentModelFactory(types);
            PublishedContentModelFactoryResolver.Current.SetFactory(factory);
        }
    }
    

    However, upon website load, I'm getting the following YSOD:

    Method not found: 'System.Object Our.Umbraco.Ditto.PublishedContentExtensions.As(Umbraco.Core.Models.IPublishedContent, System.Type, System.Globalization.CultureInfo, System.Object, System.Collections.Generic.IEnumerable1<Our.Umbraco.Ditto.DittoValueResolverContext>, System.Action1

    My two POCO's look as follows:

     public class Homepage : PublishedContentModel
    {
        public Homepage(IPublishedContent content) : base(content)  {}
    
        public string Title { get; set; }
    
        public HtmlString Description { get; set; }
    
        [UmbracoProperty]
        [UmbracoPicker]
        public Image Hero { get; set; }
    }
    

    and

       public class Image : PublishedContentModel
    {
        public Image(IPublishedContent content) : base(content) { }
    
    }
    

    my view simply calls UmbracoTemplatePage with Homepage as my model.

    Any help would be great!

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Nov 22, 2016 @ 11:58
    Lee Kelleher
    100

    Hi Gareth,

    My advice is, if you don't need to use DittoModelFactory, then take a different approach.

    I wrote the code as a prototype, then ran into all sorted of headaches with it, which I couldn't support.

    If you must use it, then it sounds like the DittoModelFactory code needs to be recompiled against the latest version of Ditto.

    The source-code can be found here:
    https://github.com/leekelleher/umbraco-ditto-labs/tree/develop/src/Our.Umbraco.Ditto.ModelFactory


    Our recommended approach is to use the DittoView<T> directive on your partial-view templates. We don't have much documentation about it yet, (we're working on it), but there is a demo site with some examples here:
    https://github.com/lars-erik/DittoDemoModelsBuilderified/tree/master/Dittoified

    I hope this helps?

    Cheers,
    - Lee

  • Gareth Wright 32 posts 101 karma points c-trib
    Nov 22, 2016 @ 12:01
    Gareth Wright
    0

    Excellent, just reverted it out for DittoView and works perfectly.

    Thanks for your help!

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Nov 22, 2016 @ 12:04
    Lee Kelleher
    0

    Awesome, glad it worked so smoothly!

Please Sign in or register to post replies

Write your reply to:

Draft