Best way to link to content item?

Topics: Customizing Orchard, General
Feb 15, 2012 at 1:48 PM

I have a TopicPage content type that contains a TopicProfilePart. There is also a TopicProfile content type (which also contains the TopicProfilePart) that I want to link to from my TopicPage. 

In the view for my TopicPage I do this: 

    TopicProfilePart profPart = Model.TopicProfilePart;
    ContentItem profItem = profPart .ContentItem;
    RoutePart profRoutePart = profItem .As(); 

Route path: @profRoutePart.Path
Route Slug: @profRoutePart.Slug

Which should I use, .Path, or .Slug? In this case the two have the same value. When would they ever be different? 

Feb 15, 2012 at 2:21 PM

Found an older post with a similar question. Looks like .Slug is relative to the container, and .Path is the absolute path. 

Is this different once I migrate to AutoRoute? 

Feb 15, 2012 at 6:34 PM

Once you have migrated, there are only aliases, which are paths.

Feb 16, 2012 at 11:31 AM

The correct way to link to a content item is: @Url.ItemDisplayUrl(content)

This way the link will be generated completely independently of the underlying routing mechanism. If AutoroutePart is there, you'll get the alias; if RoutePart is there you'll get the Path; if neither parts are there, you'll get the default action of /Contents/Item/Display/{Id}.