Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Quick question; in application code, what is the current best practice for getting a URL from a node ID, e.g. as returned from Examine?
Is it still umbraco.library.NiceUrl()?
umbraco.library.NiceUrl()
var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current); var node = umbracoHelper.TypedContent(nodeId); if(node != null) { return node.Url; } else { return null; }
not sure if there's a faster way
Hi Rob
You are right, this is the way:
Thanks,
Alex
var content= UmbracoContext.Current.ContentCache.GetById(nodeId); content.Url;
Theres a NiceUrl() and NiceUrlWithDomain() method on the UmbracoHelper. I would use that.
You can learn more about the UmbracoHelper here:
https://our.umbraco.org/Documentation/Reference/Querying/UmbracoHelper/
Hi Rob,
I would not use umbraco.library.NiceUrl because it's a legacy API. If i'm correct it will deprecated in V8
In c# code you can use :
UmbracoContext.Current.UrlProvider.GetUrl(id);
In your views you can use :
@Umbraco.Url(id)
Dave
Perfect answer - C# plus Razor examples, exactly what I was after. Thanks Dave.
Just as a correction to this, in your views it's not @(Umbraco.Url(id)) it's actually @(UmbracoContext.Url(id)) (Quite possible this changed since original posting)
@(Umbraco.Url(id))
@(UmbracoContext.Url(id))
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Best practice for getting content URLs in v7
Quick question; in application code, what is the current best practice for getting a URL from a node ID, e.g. as returned from Examine?
Is it still
umbraco.library.NiceUrl()
?not sure if there's a faster way
Hi Rob
You are right, this is the way:
Thanks,
Alex
Theres a NiceUrl() and NiceUrlWithDomain() method on the UmbracoHelper. I would use that.
You can learn more about the UmbracoHelper here:
https://our.umbraco.org/Documentation/Reference/Querying/UmbracoHelper/
Hi Rob,
I would not use umbraco.library.NiceUrl because it's a legacy API. If i'm correct it will deprecated in V8
In c# code you can use :
In your views you can use :
Dave
Perfect answer - C# plus Razor examples, exactly what I was after. Thanks Dave.
Just as a correction to this, in your views it's not
@(Umbraco.Url(id))
it's actually@(UmbracoContext.Url(id))
(Quite possible this changed since original posting)is working on a reply...