Copied to clipboard

Flag this post as spam?

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


  • Raluca Dumitru 33 posts 174 karma points
    Aug 23, 2019 @ 16:05
    Raluca Dumitru
    0

    'Link' is an ambiguous reference between 'Umbraco.Web.Models.Link' and 'Umbraco.Web.PublishedModels.Link'

    Hi there Umbraco people,

    I am trying to get the links from my multi link picker but I am getting this error.

    enter image description here

    Does anyone know what is this about, as I have used the link picker before with no issues.

    I also have to mention that I tried to use Model.Ancestors() with no luck today. It said that the Model does not contain a definition for Ancestors, so I gave up on that. But I would really like to get this multi link to work.

    Thank you.

  • Erik-Jan Westendorp 29 posts 295 karma points MVP 5x c-trib
    Aug 23, 2019 @ 16:51
    Erik-Jan Westendorp
    100

    Hi Raluca,

    This is because both namespaces, Umbraco.Web.Models and Umbraco.Web.PublishedModels contains a definition of 'Link'. You can easily solve this by changing this line of code:

    var files = doc.Value<IEnumerable<Link>>("documentFiles");
    

    to:

    var files = doc.Value<IEnumerable<Umbraco.Web.PublishedModels.Link>>("documentFiles");
    
  • Raluca Dumitru 33 posts 174 karma points
    Aug 27, 2019 @ 08:14
    Raluca Dumitru
    0

    Thank you.

    Using the first one worked for me.

     var files = doc.Value<IEnumerable<Umbraco.Web.Models.Link>>("documentFiles");
    
  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Aug 23, 2019 @ 16:54
    Nik
    2

    Along the same lines as Erik's response, except as it's in a view it might error saying it can't find web.

    If you add the following using statement at the top of the view

    @using PublishedModels = Umbraco.Web.PublishedModels
    

    Then you can do

    @doc.Value<PublishedModels.Link>("documentFiles")
    

    I think :-)

    Nik

  • Raluca Dumitru 33 posts 174 karma points
    Aug 27, 2019 @ 08:03
    Raluca Dumitru
    0

    It does not complain so I am going to accept Erik's answer as the solution.

    But yours it's a perfectly valid answer as well, if you include the IEnumerable in the query. Thank you

Please Sign in or register to post replies

Write your reply to:

Draft