November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Assuming that you've defined the link property like this:
[BackingType(typeof(PropertyUrl))]
public virtual Url Link { get; set; }
You can use the following code in your view:
@Url.ContentUrl(Model.CurrentPage.Link)
Or you can use the following code in your controller:
var urlHelper = ServiceLocator.Current.GetInstance<UrlHelper>();
var friendlyUrl = urlHelper.ContentUrl(currentPage.Link);
Hope this helps.
Thanks, found what I was looking for here.
This is one of the most confusing areas of EPiServer, getting urls to things. UrlBuilder, UrlResolver, UrlHelper, UrlRewriteProvider, PermanentLinkUtility, PermanentLinkMapStore etc. It's just too many options. It shouldn't have to be this hard.
UrlResolver should be your first stop in EPiServer 7.5+. the others are from previous versions. Hopefully that helps you decide which on to use.
Aha, is that so.
In my case the only thing that made sense was UrlHelper.
I have an Url property that I want to get the link for, outside of a view. How am I supposed to do it?
UrlHelper uses UrlResolver under the hood
public static string ContentUrl(this UrlHelper urlHelper, Url url)
{
if (url == null || url.IsEmpty())
return string.Empty;
else
return ServiceLocator.Current.GetInstance<UrlResolver>().ConvertClassicToContentUrl(url.ToString()) ?? url.ToString();
}
Turns out ConvertClassicToContentUrl cannot be accessed, it's internal.
And it in turn uses UrlBuilder. :-P
I'm having a problem when trying to render an Url from an Url property in my view. Problem is that I want the friendly URL either it's an internal nor an external link. I can get the external link correct only by typing @Url.PageUrl(Model.Link.ToString()) but for the internal link this only gives me the ID to the page. How to get this done for both internal and external links?