Pregunta

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.

¿Fue útil?

Solución 2

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);

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top