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
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.
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:
Code:
System:
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.
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
Thanks
Pasang
It works well
Thanks for your solution
Great 👍
is working on a reply...