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
    Apr 14, 2014 @ 13:44
    Claushingebjerg
    0

    Get Node url from id

    I have a node with a content picker. I need to get the url of the picked node in a view.

    var myLink = @Model.GetPropertyValue("link");

    Gives me the ID of the node

    var myLink = @Model.GetPropertyValue("link").Url;

    throws an error "Cannot assign method group to an implicitly-typed local variable", the same happens when using

    var myLink = @Model.GetPropertyValue("link").NiceUrl;

     

    What's the right way to do it?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Apr 14, 2014 @ 13:49
    Jeavon Leopold
    0

    Hi Claus,

    I would suggest this:

    var myLink = Umbraco.NiceUrl(Model.GetPropertyValue("link"));
    

    Jeavon

  • Claushingebjerg 939 posts 2574 karma points
    Apr 14, 2014 @ 13:54
    Claushingebjerg
    0

    That returns an error 

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


  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Apr 14, 2014 @ 13:55
    Jeavon Leopold
    2

    Ah ok,

    var myLink = Umbraco.NiceUrl(Model.GetPropertyValue<int>("link"));
    
  • Claushingebjerg 939 posts 2574 karma points
    Apr 14, 2014 @ 14:02
    Claushingebjerg
    0

    Im going nuts...

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Apr 14, 2014 @ 14:04
    Jeavon Leopold
    100

    You cannot have those "@" in the code blocks e.g

    var myTeaser = @Model.
    

    has to be

    var myTeaser = Model.
    
  • Claushingebjerg 939 posts 2574 karma points
    Apr 14, 2014 @ 14:08
    Claushingebjerg
    0

    OK :)

    Tjats weird, 'cause it worked fine, until i wanted the url...

    I ended up with this,, and it works. Thanks for the lesson ;)

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Apr 14, 2014 @ 14:12
    Jeavon Leopold
    0

    In some situations it will work, but it's better just to never do it. In Razor v1, you could do it a lot but Razor v2 is not so forgiving.

Please Sign in or register to post replies

Write your reply to:

Draft