Copied to clipboard

Flag this post as spam?

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


  • RefaelAzari 16 posts 86 karma points
    May 15, 2022 @ 08:48
    RefaelAzari
    0

    Nested Content

    hii :-)

    i am new in umbraco cms i am using Umbraco 9.5 with .Net Core and i trying to set document type as nested content by the nested content guide https://our.umbraco.com/Documentation/Fundamentals/Backoffice/property-editors/built-in-property-editors/Nested-Content/

    and i am getting error "ModelBindingException: Cannot bind source type ccc.Core.Models.HomePage to model type ccc.Core.Models.Advantage."

    i triyed everything and i dont know what is the problem please help me

    Document Type as Element Type

    enter image description here

    Advantage Document Type as element type:

     @using ContentModels = ccc.Core.Models;
    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.Advantage>
    @{
        var items = Model.Value<IEnumerable<IPublishedElement>>("nest");
    
        foreach (var item in items)
        {
            <div class="col-lg-4" data-aos="fade-up" data-aos-delay="200">
                <div class="box">
                    <img src="@Model.AdvantageImage" class="img-fluid" alt="">
                    <h3>@Model.AdvantageTitle</h3>
                    <p>@Model.AdvantageDescription</p>
                </div>
            </div>
        }
    }
    

    Home Page:

    @using ContentModels = ccc.Core.Models;
    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<IPublishedContent>
    @{
        Layout = "Master.cshtml";
        var homePage = Model.AncestorOrSelf<ContentModels.HomePage>();
    }
    <style>
        .buttonAlign {
            text-align: left !important;
        }
    </style>
    <!-- ======= Hero Section ======= -->
    <section id="hero" class="hero d-flex align-items-center">
        <div class="container">
            <div class="row">
                <div class="col-lg-6 d-flex flex-column justify-content-center">
                    @homePage.ContentHeaderDescription
                    <div data-aos="fade-up" data-aos-delay="600">
                        <div class="buttonAlign text-center text-lg-start">
                            @{
                                //var links = Model.Value<IEnumerable<Link>>("ButtonUrl");
                                var links = homePage.ButtonUrl;
                                if (links.Any())
                                {
    
                                    @foreach (var link in links)
                                    {
                                        <a href="@link.Url" target="@link.Target" class="btn-get-started scrollto d-inline-flex align-items-center justify-content-center align-self-center">
                                            <span>@homePage.ButtonText</span>
                                            <i class="bi bi-arrow-right"></i>
                                        </a>
                                    }
                                }
                            }
    
                        </div>
                    </div>
                </div>
                <div class="col-lg-6 hero-img" data-aos="zoom-out" data-aos-delay="200">
                    <img src="@homePage.HeaderImageSlide" class="img-fluid" alt="">
                </div>
            </div>
        </div>
    
    </section>
    <!-- End Hero -->
    <!-- ======= About Section ======= -->
    <section id="about" class="about">
        <div class="container" data-aos="fade-up">
            <div class="row gx-0">
                <div class="col-lg-8">
                    <div class="portfolio-details-slider swiper">
                        <div class="swiper-wrapper align-items-center">
                            @foreach (var image in @homePage.ContentAboutImageSlide)
                            {
                                <div class="swiper-slide">
                                    <img src="@image.GetCropUrl()" alt="">
                                </div>
                            }
                        </div>
                        <div class="swiper-pagination"></div>
                    </div>
                </div>
    
                <div class="col-lg-4">
                    <div class="content">
                        @homePage.ContentAboutDescription
                        @{
                            //var aboutLinks = Model.Value<IEnumerable<Link>>("AboutButtonUrl");
                            var aboutLinks = homePage.AboutButtonUrl;
                            if (aboutLinks.Any())
                            {
                                @foreach (var link in aboutLinks)
                                {
                                    <div class="buttonAlign text-center text-lg-start">
                                        <a href="@link.Url" target="@link.Target" class="btn-read-more d-inline-flex align-items-center justify-content-center align-self-center">
                                            <span>@homePage.AboutButtonText&nbsp;</span>
                                            @{
                                                if (Model.GetCultureFromDomains() != "he")
                                                {
                                                    <i class='bi bi-arrow-right'></i>
                                                }
                                                else
                                                {
                                                    <i class='bi bi-arrow-left'></i>
                                                }
                                            }
                                        </a>
                                    </div>
                                }
                            }
                        }
                    </div>
                </div>
            </div>
        </div>
    
    </section>
    <!-- End About Section -->
    <!-- ======= Values Section ======= -->
    <section id="values" class="values">
        <div class="container" data-aos="fade-up">
            @*<header class="section-header">
                    <h2>Our Values</h2>
                    <p>Odit est perspiciatis laborum et dicta</p>
                </header>*@
            <div class="row">
                <div class="col-lg-4" data-aos="fade-up" data-aos-delay="200">
                    @await Html.PartialAsync("NestedContent/Advantage")
                </div>
            </div>
        </div>
    </section>
    <!-- End Values Section -->
    
  • Paul Seal 524 posts 2890 karma points MVP 7x c-trib
    May 15, 2022 @ 10:16
    Paul Seal
    0

    The easy way to solve this would be to hang the Model in the partial to be HomePage instead of Advantage.

  • RefaelAzari 16 posts 86 karma points
    May 15, 2022 @ 10:18
    RefaelAzari
    0

    hii :-)

    thank you for the answer but if i want use Advantage in other pages it will work?

  • Paul Seal 524 posts 2890 karma points MVP 7x c-trib
    May 15, 2022 @ 10:21
    Paul Seal
    0

    No. In that case. Pass in the property to the partial and use that as the model. You can do that like this:

    @await Html.PartialAsync("NestedContent/Advantage", Model.AdvantageProperty)

  • RefaelAzari 16 posts 86 karma points
    May 15, 2022 @ 10:53
    RefaelAzari
    0

    i tried now i getting another error... :-(

    ModelBindingException: Cannot bind source type System.Collections.Generic.List`1[[ccc.Core.Models.Advantage, ccc.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] to model type ccc.Core.Models.Advantage.

    i saw your videos on youtube and i learned allot from the thank you for them :-) i didnt saw video about nested content with umbraco 9 and rendering it

  • Paul Seal 524 posts 2890 karma points MVP 7x c-trib
    May 15, 2022 @ 11:27
    Paul Seal
    0

    Ok now change your model to this

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<>

    I’m glad you found my videos useful.

    Paul

  • RefaelAzari 16 posts 86 karma points
    May 15, 2022 @ 11:42
    RefaelAzari
    0

    enter image description here

  • RefaelAzari 16 posts 86 karma points
    May 15, 2022 @ 11:48
    RefaelAzari
    0

    lets leave the Advantage Element eside

    What is the right way to implement nested content and rendering it with umbraco 9 with .NET core? the simpliest and basic way

    did you have code example for it?

  • Paul Seal 524 posts 2890 karma points MVP 7x c-trib
    May 15, 2022 @ 12:29
  • RefaelAzari 16 posts 86 karma points
    May 15, 2022 @ 12:49
    RefaelAzari
    100

    thanks a lot it works with ToArray()

    Home Page:

    @await Html.PartialAsync("NestedContent/Advantage",homePage.AdvantageSection.ToArray())
    

    Advantage:

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<Advantage[]>
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies