Copied to clipboard

Flag this post as spam?

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


  • Lachlann 343 posts 625 karma points
    Sep 19, 2012 @ 21:22
    Lachlann
    0

    UrlPickerState in Razor

    Hey so I am running 4.9 and have ucomponents v5.0 beta. I have a number of nodes all with a urlpicker property these nodes are in turn selected on a page using a multiple node picker.

    I am really difficulty in getting the value of the URL Picker here, the documentation seems to stop just short of my understanding and so I am a bit lost.

    When i output the value of my UrlPickerProperty I get type uComponents.DataTypes.UrlPicker.Dto.UrlPickerState but really not sure where to go from here. Any help would be really great, I have tried @n.BannerLink.Url but that errors. I have tried deserialising the value but it is epxecting a string (of course).

    I must doing something stupid but I dont know what.

    L

  • Tom Fulton 2030 posts 4996 karma points c-trib
    Sep 19, 2012 @ 22:10
    Tom Fulton
    1

    Hi,

    I think @n.BannerLink.Url should work.  But here is how you can deserialize it to get autocomplete, etc.  This uses GetPropertyValue as that always returns a string.

     UrlPickerState state = UrlPickerState.Deserialize(Model.GetPropertyValue("pieceLink"));
        if (state != null)
        {
            var targetAttr = state.NewWindow ? " target=\"blank\"" : "";
            <a href="@state.Url" title="@state.Title"@targetAttr>@state.Title</a>
        }

    HTH,
    Tom 

  • Matthias 87 posts 173 karma points
    Sep 20, 2012 @ 10:44
    Matthias
    1

    Hi,

    depending on the type of link you picked you may have to check the urlpicker mode to proceed:

    var link = @n.BannerLink;
    var href = "";

    if(@link.Mode==uComponents.DataTypes.UrlPicker.UrlPickerMode.URL){
       href = @link.Url; 
    }
    else if(@link.Mode==uComponents.DataTypes.UrlPicker.UrlPickerMode.Media){
       href = Library.MediaById(@link.NodeId).umbracoFile; 

    else if(@link.Mode==uComponents.DataTypes.UrlPicker.UrlPickerMode.Content){
       href = Library.NodeById(@link.NodeId).Url; 
    }

    <a href="@href">@link.Title</a>

    HTH
    Matthias

  • Lachlann 343 posts 625 karma points
    Sep 20, 2012 @ 19:23
    Lachlann
    0

    Hi guys

     

    Thanks so much for your answers thanks for the tips about getting serialise to work Tom!

    I have marked Matthias's repsonse as the answer as this is what I have implemented in my code and it works fine.

     

    Cheers

    L

  • 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.

Please Sign in or register to post replies