Copied to clipboard

Flag this post as spam?

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


  • bh 408 posts 1395 karma points
    Nov 16, 2018 @ 16:32
    bh
    0

    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 2141 posts 14324 karma points MVP 8x 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 408 posts 1395 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 2141 posts 14324 karma points MVP 8x 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