Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 karma points
    Jun 27, 2014 @ 09:15
    Claushingebjerg
    0

    get url from nodeid

    Im slowly going crazy... Simple as it is, cant get it to work :|

    myLink returns "1061" but this doesn't work...

    @{ 
        var myLink = @fieldset.GetValue("slideLink");
    }
    <a href="@umbraco.library.NiceUrl(myLink)">Click</a>


    This works (but is not very usable :) :

    <a href="@umbraco.library.NiceUrl(1061)">Click</a>
  • Dan Lister 416 posts 1974 karma points c-trib
    Jun 27, 2014 @ 09:25
    Dan Lister
    0

    What type is fieldset? Have you tried something like the following, assuming your fieldset is of type IPublishedContent? 

    @{
        var id = fieldset.GetPropertyValue<int>("slideLink");
        var url = Umbraco.NiceUrl(id);
    }

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 27, 2014 @ 09:28
    Jeavon Leopold
    0

    Archetype?

       @{ 
            var myLink = fieldset.GetValue<int>("slideLink");
        }
        <a href="@Umbraco.NiceUrl(myLink)">Click</a>
    
  • Claushingebjerg 939 posts 2574 karma points
    Jun 27, 2014 @ 09:29
    Claushingebjerg
    0

    Yup tried that, you cant <int>, it returns an errror.

    .fieldset is an archetype

  • Stefan Kip 1614 posts 4131 karma points c-trib
    Jun 27, 2014 @ 09:30
    Stefan Kip
    100

    How about:

    @umbraco.library.NiceUrl(int.Parse(myLink))
    
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 27, 2014 @ 09:32
    Jeavon Leopold
    0

    You had a @ in the variable before, did you try without that?

  • Claushingebjerg 939 posts 2574 karma points
    Jun 27, 2014 @ 09:35
    Claushingebjerg
    0

    Thanks kip, that did it.

    Yeah Jeavon tried it noth with and without

    var myLink = fieldset.GetValue<int>("slideLink");

    and

    var myLink = @fieldset.GetValue<int>("slideLink");

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 27, 2014 @ 09:41
    Jeavon Leopold
    1

    Ok, I will investigate further. In the meantime to avoid obsolete umbraco.library this should work:

       <a href="@Umbraco.NiceUrl(int.Parse(myLink))">Click</a>
    
  • Claushingebjerg 939 posts 2574 karma points
    Jun 27, 2014 @ 09:47
    Claushingebjerg
    0

    Yup, thanks

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 27, 2014 @ 11:21
    Jeavon Leopold
    0

    I've just tried this and it worked fine:

    @foreach (var fieldset in Model.Content.GetPropertyValue<ArchetypeModel>("myarchetype"))
    {
        if (fieldset.HasValue("slideLink"))
        {
            var myLink = fieldset.GetValue<int>("slideLink");
            <a href="@Umbraco.NiceUrl(myLink)">Click</a>
        }
    }
    

    So, I'm going to guess that you had a slideLink without a value. Adding the fieldset.HasValue deals with this to prevent the exception.

  • Claushingebjerg 939 posts 2574 karma points
    Jun 27, 2014 @ 11:33
    Claushingebjerg
    0

    Well... I had to change the for each, because i wanted to check if a node was first... So i have:

    @{
         var slider = Model.Content.GetPropertyValue<ArchetypeModel>("slider");
         foreach (var fieldset in slider)
        {
            if (fieldset.Equals(slider.First()))
            {
            <div class="item active">
                <div class="carousel-caption">
    @{ var myLink = @fieldset.GetValue("slideLink"); } <a href="@Umbraco.NiceUrl(int.Parse(myLink))"><p>@Html.Raw(myStrippedText)</p></a> </div> </div> }
    }

    and adding the <int> here causes an error...

     

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 27, 2014 @ 11:37
    Jeavon Leopold
    0

    How about like this:

    @{
        var slider = Model.Content.GetPropertyValue<ArchetypeModel>("slider");
        foreach (var fieldset in slider)
        {
            if (fieldset.Equals(slider.First()))
            {
                <div class="item active">
                    <div class="carousel-caption">                 
                        @if (fieldset.HasValue("slideLink"))
                        {
                            var myLink = fieldset.GetValue<int>("slideLink");
                            <a href="@Umbraco.NiceUrl(myLink)"><p>something</p></a>
                        }                   
                    </div>
                </div>
            }
        }
    }       
    
Please Sign in or register to post replies

Write your reply to:

Draft