Archetype icon indicating copy to clipboard operation
Archetype copied to clipboard

Fail to convert the value when GetValue<int>() ?

Open bhagirathpancholisa opened this issue 7 years ago • 3 comments

hello , i tried below solution and at debugging stag i get value on imageurl but still linkurl is getting null. can u solve this? i tried this solution given by @kjac @samsam321 . refer below https://github.com/kgiszewski/Archetype/issues/413 below is my code.i am using umbraco 7.7.4 version. and follow paul sean videos on umbraco.https://www.youtube.com/watch?v=tabQKn1JZkM&t=1798s.

 var mediaItem = fieldset.GetValue<IPublishedContent>("image");
                string imageUrl = mediaItem.Url;

                var linkTopage = fieldset.GetValue<IPublishedContent>("page");
                string linkUrl = linkTopage.Url;


 model.Add(new FeaturedItem(fieldset.GetValue<string>("name"), fieldset.GetValue<string>("category"), imageUrl, linkUrl))

1 2

bhagirathpancholisa avatar Nov 01 '17 05:11 bhagirathpancholisa

Hi bhagirathpancholisa,

I've just spent 2 hours battling what seems like the same issue. I have an Archetype setup with 2 properties: text and icon (text is a textbox, icon is a media picker).

No matter what I tried I kept getting null for the icon. I started to debug the issue and found out that I COULD retrieve the image ID for icon - but as soon as I tried to use it with e.g. Umbraco.Media - I simply got a null exception.

After a lot of debugging I finally found a solution to my problem - I hope it might help you out as well:

When retrieving the Archetype model:

var icons = Model.Content.GetPropertyValue<ArchetypeModel>("ikoner");

I found that the model contained an extra item for the fieldset - so when I did this:

@foreach (var icon in icons) { var image = icon.GetValue<IPublishedContent>("ikon"); var text = icon.GetValue("tekst");

                <div class="cell auto">
                    <h4>
                        @image.Url
                    </h4>
                    <h3>
                        @text
                    </h3>
                </div>

}

I would get the first item without any properties. Which in turn would return a null pointer exception.

However - THIS works perfect:

@foreach (var icon in icons.Skip(1)) { }

So simply by skipping the first item, I got it working! :)

Hope it helps you out.

inversiondk avatar Feb 21 '18 18:02 inversiondk

hi @inversiondk thank you for your time. I learn something new today.but my problem has been solved. i used "Related Links" property. here is my code at back-end side

` IPublishedContent homepage = CurrentPage.AncestorOrSelf("home"); Lists = homepage.GetPropertyValue<ArchetypeModel>("aliseName");

        foreach (ArchetypeFieldsetModel fieldset in Lists )
        {

var rblink = fieldset.GetValue<RelatedLinks>("buttonUrl"); //RelatedLink var btnurl = rblink != null ? rblink.FirstOrDefault().Link : string.Empty;

var mediaItem = fieldset.GetValue<IPublishedContent>("image"); //media picker string imageUrl = string.Empty; if (mediaItem != null) imageUrl = mediaItem.Url; }`

bhagirathpancholisa avatar Feb 22 '18 05:02 bhagirathpancholisa

@inversiondk i tried with your way. but i got this error "ipublishcontent does not contain a defination for "content" missing assembly reference on partial view." and "foreach statement cannot operate on variables of type object because object does not contain public defination for 'getenumerator"' could you please help me with this. or give me your sample code. see code in image

foreach_error

bhagirathpancholisa avatar Feb 26 '18 07:02 bhagirathpancholisa