.Name gives "cannot convert from 'method group' to 'HelperResult'"
On a document type I have a nested content property "ribbons". One type of ribbon build upon a document type with one field "ribbonItems" of type Multi Node Tree Picker where editors can choose nodes to list in the ribbon.
Below are two versions of my code (some null checks and other stuff is removed for clarity). It is the latter that I would like to get working:
Works, but does not include fetching node name:
var ribbons = Model.Value<IEnumerable<IPublishedElement>>("ribbons").Where(x => x.IsVisible());
foreach (var ribbon in ribbons)
{
var ribbonItems = ribbon.Value<IEnumerable<IPublishedElement>>("ribbonItems");
if (ribbonItems != null && ribbonItems.Any())
{
foreach (var ribbonItem in ribbonItems)
{
<h2>@ribbonItem.Value("headline")</h2>
@ribbonItem.Value("text")
}
}
}
Works, but gives error:
var ribbons = Model.Value<IEnumerable<IPublishedElement>>("ribbons").Where(x => x.IsVisible());
foreach (var ribbon in ribbons)
{
var ribbonItems = ribbon.Value<IEnumerable<IPublishedElement>>("ribbonItems");
if (ribbonItems != null && ribbonItems.Any())
{
foreach (var ribbonItem in ribbonItems)
{
<h2>@ribbonItem.Name</h2>
@ribbonItem.Value("text")
}
}
}
The error: "CS1503: Argument 1: cannot convert from 'method group' to 'HelperResult'" for the line with "@ribbonItem.Name"
(you'd expect it to if you have been working with V7 and IPublishedContent that does have that property!)
But I think, because Element Types are created as part of Nested Content or Block editor, they don't really have a 'name' in the same way as a published item in the Content tree would.
According to your question, the property ribbonItems is a Multi Node Tree Picker (MNTP), but you are currently retrieving the contents as IEnumerable<IPublishedElement>, which as Marc mentions doesn't have a Name property.
As a MNTP references real content nodes it actually returns IEnumerable<IPublishedContent> so if you switch over to that you should find that Name becomes available and is no longer an issue for you.
I have marked Niks anwers as a solution since he answered first in the copy of mu question in the Umbraco Web Developers forum (https://www.facebook.com/groups/202933450108554/permalink/1183692555365967/)
.Name gives "cannot convert from 'method group' to 'HelperResult'"
On a document type I have a nested content property "ribbons". One type of ribbon build upon a document type with one field "ribbonItems" of type Multi Node Tree Picker where editors can choose nodes to list in the ribbon.
Below are two versions of my code (some null checks and other stuff is removed for clarity). It is the latter that I would like to get working:
Works, but does not include fetching node name:
Works, but gives error:
The error: "CS1503: Argument 1: cannot convert from 'method group' to 'HelperResult'" for the line with "@ribbonItem.Name"
How can I fetch the node name of a ribbonItem?
Hi Martin
I think it's because it's an IPublishedElement you have here and IPublishedElement doesn't have a 'Name' property:
https://github.com/umbraco/Umbraco-CMS/blob/3bfd9b71e290354744d677440983ecd06c5c0788/src/Umbraco.Core/Models/PublishedContent/IPublishedElement.cs
(you'd expect it to if you have been working with V7 and IPublishedContent that does have that property!)
But I think, because Element Types are created as part of Nested Content or Block editor, they don't really have a 'name' in the same way as a published item in the Content tree would.
regards
Marc
Hey Martin,
According to your question, the property
ribbonItems
is a Multi Node Tree Picker (MNTP), but you are currently retrieving the contents asIEnumerable<IPublishedElement>
, which as Marc mentions doesn't have a Name property.As a MNTP references real content nodes it actually returns
IEnumerable<IPublishedContent>
so if you switch over to that you should find that Name becomes available and is no longer an issue for you.Cheers
Nik
Hi Marc and Nik,
Thank you, both! :)
I have marked Niks anwers as a solution since he answered first in the copy of mu question in the Umbraco Web Developers forum (https://www.facebook.com/groups/202933450108554/permalink/1183692555365967/)
is working on a reply...
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.