Reputation: 1350
I'm using Archetype property editor and trying to grab only the first fieldset using foreach:
foreach (var fieldset in Umbraco.Content(5369).GetPropertyValue<Archetype.Models.ArchetypeModel>("myProperty"))
{
var icon = Umbraco.TypedMedia(fieldset .GetValue("icon"));
<img src="@icon.Url" />
<span>@fieldset.GetValue("iconTitle")</span>
}
Fieldset is of type {Archetype.Models.ArchetypeFieldsetModel}. How can I get only the first fieldset ?
EDIT Tried:
var fieldset = Umbraco.Content(5369).GetPropertyValue<Archetype.Models.ArchetypeModel>("hotelFacilitesIcons").Fieldsets;
This gives me Archetype.Models.ArchetypeModel.Fieldsets' is inaccessible due to its protection level
Tried:
var fieldset = Umbraco.Content(5369).GetPropertyValue<Archetype.Models.ArchetypeModel>("myPropertyAlias");
var facility = fieldset.GetPropertyValue<List<Archetype.Models.ArchetypeFieldsetModel>>("myFieldSetAlias");
This gives me: 'Archetype.Models.ArchetypeModel' does not contain a definition for 'GetPropertyValue'
from second line
Upvotes: 0
Views: 3154
Reputation: 538
I have sort of done the same thing in my case wanted to make sure the first archetype has got its first value set before getting all the others so how i got around it was by creating a var with the archetypes (which will give you a list fo one or more) then get the first one and check its value like below;
var contentSectionArchtype = Model.Content.GetPropertyValue<ArchetypeModel>("myArchetypeAlias");
var firstSection = contentSectionArchtype.First();
then the first section was always the first archetype which i would then check its first value before looping through all of them, hope that helps.
Upvotes: 1
Reputation: 3692
I'll have a stab at perhaps trying to point you in the right direction. Looking at a previous project I have been involved in there is a Archetype.Models.ArchetypeFieldsetModel
type so perhaps your content property might return a collection of Archetype.Models.ArchetypeFieldsetModel
instead of Archetype.Models.ArchetypeModel
?
E.g.
var fieldset = Umbraco.Content(5369).GetPropertyValue<List<Archetype.Models.ArchetypeFieldsetModel>>("myProperty").FirstOrDefault();
var icon = Umbraco.TypedMedia(fieldset .GetValue("icon"));
<img src="@icon.Url" />
<span>@fieldset.GetValue("iconTitle")</span>
Upvotes: 2