Copied to clipboard

Flag this post as spam?

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


  • Stefan080106 3 posts 33 karma points
    Aug 20, 2022 @ 22:08
    Stefan080106
    0

    partial views not work

    Hey!
    I'm play today a little bit with umbraco to learn it with c#. After little start errors run the system now and i can work with that in Visual Studio. But now i have try to create a new "partial view" for the navigation with the template code, but if i reload the page they print errors. I understand the errors but i don't know what i can do for fix.

    Errors:

    "IPublishedContent" does not contain a definition for "content", and no accessible content extension method could be found that accepts an initial argument of type "IPublishedContent" (possibly missing a using directive or assembly reference).
    
    @{ var selection = Model?.Content.Root().Children.Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }
    


     "IPublishedContent" enthält keine Definition für "Content", und es konnte keine zugängliche Content-Erweiterungsmethode gefunden werden, die ein erstes Argument vom Typ "IPublishedContent" akzeptiert (möglicherweise fehlt eine using-Direktive oder ein Assemblyverweis).
    
        @if (selection?.Length > 0)
        {
            <ul>
                @foreach (var item in selection)
                {
                    <li class="@(item.IsAncestorOrSelf(Model?.Content) ? "current" : null)">
                        <a href="@item.Url(PublishedUrlProvider)">@item.Name</a>
                    </li>
                }
            </ul>
        }
    


    Argument "1": Conversion from "method group" to "object?" not possible.
    
    @if (selection?.Length > 0)
    {
        <ul>
            @foreach (var item in selection)
            {
                <li class="@(item.IsAncestorOrSelf(Model?.Content) ? "current" : null)">
                    <a href="@item.Url(PublishedUrlProvider)">@item.Name</a>
                </li>
            }
        </ul>
    }
    

    Code:

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
    @using Umbraco.Cms.Core
    @using Umbraco.Cms.Core.Models.PublishedContent
    @using Umbraco.Cms.Core.Routing
    @using Umbraco.Extensions
    
    @inject IPublishedValueFallback PublishedValueFallback
    @inject IPublishedUrlProvider PublishedUrlProvider
    @*
        This snippet displays a list of links of the pages immediately under the top-most page in the content tree.
        This is the home page for a standard website.
        It also highlights the current active page/section in the navigation with the CSS class "current".
    *@
    
    @{ var selection = Model?.Content.Root().Children.Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }
    
    @if (selection?.Length > 0)
    {
        <ul>
            @foreach (var item in selection)
            {
                <li class="@(item.IsAncestorOrSelf(Model?.Content) ? "current" : null)">
                    <a href="@item.Url(PublishedUrlProvider)">@item.Name</a>
                </li>
            }
        </ul>
    }
    

    System:

    • Operating system name Microsoft Windows 11 Pro Insider Preview
    • Processor AMD Ryzen 5 3500X 6-Core Processor, 3593 MHz, 6 core(s), 6 logical processor(s)
    • Microsoft Visual Studio Community 2022 Version 17.3.1 VisualStudio.17.Release/17.3.1+32811.315 Microsoft .NET Framework Version 4.8.09032
      Version installed: Community
      ASP.NET and Web Tools 17.3.375.53775
      ASP.NET and Web Tools
      C#-Tools 4.3.0-3.22401.3+41ae77386c335929113f61d6f51f2663d2780443
      C# components used in the IDE. Depending on your project type and related settings, a different version of the compiler may be used.
  • Pasang Tamang 258 posts 458 karma points
    Aug 21, 2022 @ 05:02
    Pasang Tamang
    100

    Hi Stefan,

    If you are using Umbraco 8+ then it should be Model.Root(). As you have posted this question marking Umbraco 9, below is how your code should be

    var selection = Model.Root().Children.Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); 
    

    Thanks

    Pasang

  • Stefan080106 3 posts 33 karma points
    Aug 21, 2022 @ 19:04
    Stefan080106
    0

    It works well

    Thanks for your solution

  • Pasang Tamang 258 posts 458 karma points
    Aug 22, 2022 @ 06:25
    Pasang Tamang
    0

    Great 👍

  • 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