Copied to clipboard

Flag this post as spam?

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


  • Sibren 40 posts 212 karma points c-trib
    Aug 05, 2019 @ 11:52
    Sibren
    0

    IPublishedElement-mapping Umbraco 8.1

    Hi Andy,

    Thanks for this package, it looks pretty awesome. I saw you created something to make the IPublishedElement working too.

    Unfortunately, I cannot get it to work. My ActionResult is this:

            public ActionResult Render(string property) {
            var result = new List<BaseBlockModel>();
            var mapper = new UmbracoMapper();
            foreach (var publishedElement in CurrentPage.Value<IEnumerable<IPublishedElement>>(property))
            {
                if (publishedElement.ContentType.Alias == "BlockCases")
                {
                    var viewModel = new BlockCases();
    
                    var publishedContent = publishedElement as IPublishedContent;
    
                    mapper.Map(publishedElement, viewModel);
                    result.Add(viewModel);
                }
            }
    
            return PartialView(result);
        }
    

    And my model looks like this:

        public class BlockCases : BaseBlockModel {
    
        public BlockCases()
        {
    
        }
    
        [PropertyMapping]
        public string Title { get; set; }
    
        [PropertyMapping]
        public HtmlString Text { get; set; }
    
        [PropertyMapping]
        public Link Cta { get; set; }
    
        public List<SquareItemViewModel> Cases { get; set; }
    
        [PropertyMapping]
        public string OverviewText { get; set; }
    
        /// <summary>
        /// todo
        /// </summary>
        public string OverviewLink { get; set; }
    }
    

    Please excuse the bad naming and lack of descriptions. It's not my code and I'm first getting it to work, then refactor.

    Removing the [PropertyMapping] or the empty constructor doesn't change anything.

    Could you help me out? Thanks in advance!

  • Sibren 40 posts 212 karma points c-trib
    Aug 05, 2019 @ 11:54
    Sibren
    0

    Oh, btw:

    mapper.MapCollection(CurrentPage.Value<IEnumerable<IPublishedElement>>(property), result);
    

    Does work, but I have different doctypes, so I cannot map them to a generric type.

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Aug 05, 2019 @ 11:56
    Andy Butland
    0

    Just from a quick look, can you confirm your variable publishedContent, when cast as IPublishedContent, isn't null?

    Andy

  • Sibren 40 posts 212 karma points c-trib
    Aug 05, 2019 @ 12:05
    Sibren
    0

    Hi Andy,

    I am sorry, I should have removed that line. I am loading in the publishedElement, not the publishedContent.

    My model contains: public List

    I am now using

    [PropertyMapping(Ignore = true)]
    

    on that property and now it seems to work.

    Thanks!!

  • Lewis Smith 211 posts 620 karma points c-trib
    Aug 19, 2019 @ 16:19
    Lewis Smith
    0

    Hi Sibren,

    Im having the same issue, could you share your working code so I can see where im going wrong?

    Lewis

Please Sign in or register to post replies

Write your reply to:

Draft