How to resolve page URLs in MVC application

Andy Bochmann asked on March 18, 2019 19:38

Hello,

On my MVC site, I'd like to add links (e.g. for navigation). The destination of those links should be configured in Kentico, by using the Page Selector control.

The Page Selector control returns the NodeGUID. I'm now trying to resolve the URL to specific pages by using this NodeGUID. When I try to use the RelativeURL property of the document, I often get no useful result or the result doesn't include the culture. It seems like this call doesn't take the URL Pattern for my page types into account.

var url = DocumentHelper.GetDocuments()
    .WhereEquals("NodeGUID", nodeGuid)
    .FirstOrDefault()
    .RelativeURL;

Kentico already knows the URL Pattern for these pages, e.g. /{%DocumentCulture%}/Products/{%NodeAlias%} and the Page tab in the Pages application shows the correct page for each item in my content tree.

Is there a way to resolve the same URL Pattern for a NodeGUID inside the MVC application, so that I can easily link to other pages using the Page Selector control?

Thanks

Correct Answer

Andy Bochmann answered on March 18, 2019 22:31

It works now.

In order to get the correct RelativeURL, I needed to include DocumentCulture and NodeAlias in the document query. Without it, the RelativeURL contains blank items.

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.