Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 886 posts 2415 karma points
    Apr 14, 2020 @ 17:33
    Claushingebjerg
    0

    multi url picker in 8.6

    So im trying to use the MUP in a navigation to let the editor add external links to a nav. I have the nav in a partial.

    Im basically doing this:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @using Umbraco.Web
     ---   
    @foreach (var item in menuPages) {
      var myLink = item.Value<Link>("theLink");
      @if (myLink != null)
          {
           <a href="myLink.Url">@item.Name</a>
          } else {
           <a href="@item.Url">@item.Name</a>
          }
    }
    

    but it doesn't work. Doing "item.Value("theLink")" without returns the error "cannot convert from 'method group' to 'HelperResult'"

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Apr 14, 2020 @ 17:46
    Alex Skrypnyk
    0

    Hi,

    How many items do you have selected in the MUP? If you have selected few items use this code -

    var links = Model.Value<IEnumerable<Link>>("footerLinks");
    

    If Max number of items is configured to 1

    var link = Model.Value<Link>("link");
    

    There is a difference in one or few Links

    Thanks,

    Alex

  • Claushingebjerg 886 posts 2415 karma points
    Apr 14, 2020 @ 18:03
    Claushingebjerg
    0

    enter image description here

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Apr 14, 2020 @ 18:10
    Alex Skrypnyk
    0

    Maybe the issue is in this piece of code? =

    @if (myLink != null)
          {
           <a href="myLink.Url">@item.Name</a>
          } else {
           <a href="@item.Url">@item.Name</a>
          }
    

    probably it should be:

    @if (myLink != null)
          {
           <a href="@myLink.Url">@item.Name</a>
          } 
    
  • Claushingebjerg 886 posts 2415 karma points
    Apr 14, 2020 @ 18:16
    Claushingebjerg
    1

    hehe yeah, that would fix the href for sure :)

    The problem is it never gets that far, as the if statement "@if (myLink != null)" is never true. Even if links are defined...

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Apr 14, 2020 @ 18:28
    Alex Skrypnyk
    0

    There are only 2 things that can be wrong - property alias "theLink" or the type "Link"

    Can you check both?

    And if all of these are correct - then I would recommend you to debug the code and check what value exactly is stored in item.Value("theLink")?

  • Claushingebjerg 886 posts 2415 karma points
    Apr 14, 2020 @ 18:42
    Claushingebjerg
    0

    "item.Value("theLink")" returns "Umbraco.Web.Models.Link"

    Please note that im using "@using Umbraco.Web" where the documentation uses "@using Umbraco.Web.Models"

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Apr 14, 2020 @ 19:57
    Alex Skrypnyk
    100

    Try this code:

    item.Value<Umbraco.Web.Models.Link>
    
  • Claushingebjerg 886 posts 2415 karma points
    Apr 15, 2020 @ 05:43
    Claushingebjerg
    0

    SUCCES! thanks a lot.

  • 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