Copied to clipboard

Flag this post as spam?

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


  • bh 444 posts 1544 karma points
    Nov 16, 2018 @ 16:32
    bh
    0

    Maybe a bug report

    In two separate instances on my current project, I've tried using "Min Items" on my nested content property editor, and that causes the property editor to return null even when it it's populated. When I set "Min Items" to 0 it doesn't return null. I'm running v7.12.3

    Here's my null check in case how I'm checking for null is incorrect for nested content.

    @if (Model.GetPropertyValue<IEnumerable<IPublishedContent>>("multifamilyTeam") != null)
                {
                    @Html.Partial("nc5050", Model.GetPropertyValue<IEnumerable<IPublishedContent>>("multifamilyTeam"))
                }
    
  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Nov 18, 2018 @ 21:49
    Marc Goodson
    1

    Hi bh

    When you use min items - are you setting it to 1? and are you also setting maxItems to 1?

    Looking at the Property Value Converter for Nested Content:

    https://github.com/umbraco/Umbraco-CMS/blob/1bb593d264a085f94a3ce3bd710392b350561430/src/Umbraco.Web/PropertyEditors/ValueConverters/NestedContentPublishedPropertyTypeExtensions.cs#L20

    If you have both min and max items set to be 1, then it identifies the implementation as a SingleNestedContentProperty, and instead of returning an IEnumerable

    Soooo, when you have them both set to 1, you'd access the value like so:

    @if (Model.GetPropertyValue<IPublishedContent>("multifamilyTeam") != null)
                {
                    @Html.Partial("nc5050", Model.GetPropertyValue<IPublishedContent>("multifamilyTeam"))
                }
    

    regards

    Marc

  • bh 444 posts 1544 karma points
    Nov 19, 2018 @ 20:34
    bh
    0

    Here's the error message I get using this snippet..

    @if (Model.GetPropertyValue<IPublishedContent>("cmuHeader") != null)
        {
            @Html.Partial("ncBusinessUnitHeader", Model.GetPropertyValue<IPublishedContent>("cmuHeader"))
        }
    

    Cannot bind source type Umbraco.Web.PublishedContentModels.NcBusinessUnitHeader to model type System.Collections.Generic.IEnumerable`1[[Umbraco.Core.Models.IPublishedContent, Umbraco.Core, Version=1.0.6837.12334, Culture=neutral, PublicKeyToken=null]]. The source is a ModelsBuilder type, but the view model is not. The application is in an unstable state and should be restarted.

  • Marc Goodson 2155 posts 14406 karma points MVP 9x c-trib
    Nov 19, 2018 @ 22:31
    Marc Goodson
    0

    Hi Bh

    This is now a different issue...

    Essentially you are sending to your partial 'ncBusinessUnitHeader' an object of type NcBusinessUnitHeader (which will implement IPublishedContent) but I suspect the Model or Inherits statement at the top of your 'ncBusinessUnitHeader' partial view, is expecting an IEnumerable

    So if you change that statement at the top of the 'ncBusinessUnitHeaer' partial view to be IPublishedContent instead of IEnumerable

    that should get you past that error!

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft