Copied to clipboard

Flag this post as spam?

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


  • Ajju 25 posts 148 karma points
    Feb 16, 2018 @ 04:16
    Ajju
    0

    Deserializing @Umbraco.Field

    Hello,

    I have Json value rendered from @Umbraco.Field and I want it to display one property among them.

    @Umbraco.Field("propertyName").link is right way? Suggestions please

    enter image description here

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Feb 16, 2018 @ 08:07
    Alex Skrypnyk
    0

    Hi Ajju

    Are you talking about Related Links property editor?

    Then use this code

    @using Umbraco.Web.Models
    @{
        var typedRelatedLinksConverted = Model.Content.GetPropertyValue<RelatedLinks>("footerLinks");
    
        if (typedRelatedLinksConverted.Any())
        {
            <ul>
                @foreach (var item in typedRelatedLinksConverted)
                {
                    var linkTarget = (item.NewWindow) ? "_blank" : null;
                    <li><a href="@item.Link" target="@linkTarget">@item.Caption</a></li>
                }
            </ul>
        }
    }
    

    https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/Related-Links2#mvc-view-example-value-converters-enabled

  • Ajju 25 posts 148 karma points
    Feb 17, 2018 @ 03:28
    Ajju
    0

    Thanks Alex for your reply..

    I am getting the following error after adding above(I tried the before your comment but just for you and checked again)

    Compiler Error Message: CS0246: The type or namespace name 'RelatedLinks' could not be found (are you missing a using directive or an assembly reference?)
    

    I have added the below as well and any other needs to added?

    @using Umbraco.Web.Models
    

    I have only one value for RelatedLinks to render, is that required for foreach statement or could be done with other

    Please advice where I am doing wrong

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Jan 14, 2019 @ 00:24
    Alex Skrypnyk
    100

    Hi Ajju

    If you are using not latest Umbraco version, try this code:

    @using Newtonsoft.Json.Linq
    @{      
        if (Model.Content.HasValue("relatedLinks") && Model.Content.GetPropertyValue<string>("relatedLinks").Length > 2)
        {
            <ul>
                @foreach (var item in Model.Content.GetPropertyValue<JArray>("relatedLinks"))
                {
                    var linkUrl = (item.Value<bool>("isInternal")) ? Umbraco.NiceUrl(item.Value<int>("internal")) : item.Value<string>("link");
                    var linkTarget = item.Value<bool>("newWindow") ? "_blank" : null;
                    <li><a href="@linkUrl" target="@linkTarget">@(item.Value<string>("caption"))</a></li>
                }
            </ul>
        }
    }  
    
  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Jan 30, 2019 @ 08:23
    Alex Skrypnyk
    0

    Hi Ajju

    Did you solve the issue? Is this topic solved?

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft