Rik
Rik

Reputation: 29243

Get the Url for a content item from within an ApiController in Orchard

Is there a way for a the display Url for a certain content item in an ApiController? In a regular MVC Controller I can do

Url.ItemDisplayUrl(item)

I want to be able to do something similar from an ApiController.

Upvotes: 1

Views: 1399

Answers (2)

Rik
Rik

Reputation: 29243

You can create an instance of System.Web.Mvc.UrlHelper (the type of the Url property in a regular MVC controller) using

var myUrlHelper = new System.Web.Mvc.UrlHelper(HttpContext.Current.Request.RequestContext);

If you add using Orchard.Mvc.Html; to the top, you can do

myUrlHelper.ItemDisplayUrl(item);

Upvotes: 1

jmgomez
jmgomez

Reputation: 742

If you take a look at ContentItemExtensions you will see that the url is retrieved from the metadata. If you're using AutoroutePart you can get it from there too.

Upvotes: 1

Related Questions