Copied to clipboard

Flag this post as spam?

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


  • Johan 188 posts 380 karma points
    Jun 23, 2014 @ 12:31
    Johan
    0

    Related links error

    I upgraded Umbraco to 7.1.4 an Archetype to the new 1.2.1 beta. And this snippet stopped working.

    @if (fieldset.HasValue("links")) {
        foreach (var item in fieldset.GetValue<JArray>("links")) {
            var linkUrl = (item.Value<bool>("isInternal")) ? Umbraco.NiceUrl(item.Value<int>("link")) : item.Value<string>("link");
            var linkTarget = item.Value<bool>("newWindow") ? " target=\"_blank\"" : string.Empty;
            <a class="cf related-link" href="@linkUrl" @Html.Raw(linkTarget)>@(item.Value<string>("title"))</a>
        }
    }
    

    On the third line, Umbraco nice url want an int Umbraco.NiceUrl(item.Value<int>("link")) but i get the error

    Input string was not in a correct format

    And if i give it a string Umbraco.NiceUrl(item.Value<string>("link")) Umbraco Nice URL says:

    The best overloaded method match for 'Umbraco.Web.UmbracoHelper.NiceUrl(int)' has some invalid arguments

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jun 23, 2014 @ 19:14
    Jeavon Leopold
    100

    Hi Johan,

    Try this:

    @foreach (var fieldset in Model.Content.GetPropertyValue<ArchetypeModel>("myarchetype"))
    {
        if (fieldset.HasValue("links"))
        {
            foreach (var item in fieldset.GetValue<JArray>("links"))
            {
                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 class="cf related-link" href="@linkUrl" target="@linkTarget">@(item.Value<string>("caption"))</a></li>
            }
    
    
        }
    }
    

    I think it should solve your issue.

    Jeavon

  • Johan 188 posts 380 karma points
    Jun 24, 2014 @ 15:46
    Johan
    0

    Awesome! Webmatrix is whining but it works flawlessly.

    <3

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jun 25, 2014 @ 15:52
    Jeavon Leopold
    0

    Awesome, what does WebMatrix whine about?

Please Sign in or register to post replies

Write your reply to:

Draft