Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1282 posts 2739 karma points
    Jan 28, 2014 @ 19:07
    Amir Khan
    0

    Razor version of nicurl to get url from id in template

    What is the razor equivalent of this?

    {umbraco.library:NiceUrl(1227)}

     

    I've tried @umbraco.Url(1234) and various others with no luck. Am I missing something simple here?

  • Amir Khan 1282 posts 2739 karma points
    Jan 28, 2014 @ 19:11
    Amir Khan
    0

    Here it is! @Umbraco.NiceUrl(1234)

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 28, 2014 @ 20:48
    Fuji Kusaka
    0

    You can make use of

    umbraco.library.NiceUrl(id)

     

  • Mike Chambers 635 posts 1252 karma points c-trib
    Jan 29, 2014 @ 15:18
    Mike Chambers
    0

    depends on your context though... not sure on the behind the scenes.. but I'd say that umbraco.library.NiceUrl(int Id) was an older way of doing things taken from .net usercontrols... and I'd think the below were more "Razor", also not sure which ones might inadventently hit the database :-)

    eg

    Model.Url

     

    Library.NodeById(1234).Url

     

    foreach (var item in @Model.Children){
    item.Url}

     

     DynamicNode dn = new DynamicNode(1234);
    dn.Url
  • Amir Khan 1282 posts 2739 karma points
    Jan 29, 2014 @ 17:14
    Amir Khan
    0

    So, is there a way to get a path to an image in the same way?

  • Mike Chambers 635 posts 1252 karma points c-trib
    Jan 29, 2014 @ 17:22
    Mike Chambers
    0

    http://our.umbraco.org/Documentation/Reference/Management-v6/Models/Media for the latest v6 MediaService stuff... (not moved onto it yet as we're still v4.11 and webforms with razor)

    but pre v6..

    there is a Library.MediaById(1234).umbracoFile that would give you the url to the image.

  • Mike Chambers 635 posts 1252 karma points c-trib
    Jan 29, 2014 @ 17:26
    Mike Chambers
    1

    Infact this might be for you too..  the latest and greatest in v6 MVC.

    http://our.umbraco.org/documentation/Reference/Mvc/querying

     

  • Amir Khan 1282 posts 2739 karma points
    Jan 29, 2014 @ 17:55
    Amir Khan
    0

    Thanks Mike! I always forget that we have good documentation now on Our, here's what did it for me: @Umbraco.Media(1841).Url

Please Sign in or register to post replies

Write your reply to:

Draft