3
當我在一個視圖交替的時候,我知道我可以用得到ContentItem的顯示網址:獲取果園ContentItem顯示網址
@Url.ItemDisplayUrl(contentItem)
但我不知道怎麼弄的當我在控制器上下文中時顯示URL(ActionResult)。對於站點地圖,我需要列出的ContentItems的URL。我正在使用下面的代碼。
public class SiteMapResult : ActionResult
{
readonly IContentManager _contentManager;
readonly ITagService _tagService;
public SiteMapXmlResult(IContentManager contentManager, ITagService tagService)
{
_contentManager = contentManager;
_tagService = tagService;
}
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.ContentType = "text/xml";
string host = context.HttpContext.Request.Url.Host;
StringBuilder xml = new StringBuilder();
xml.Append(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
xml.Append(@"<urlset xmlns=""http://www.sitemaps.org/schemas/sitemap/0.9"">");
var contentItems = _contentManager.Query(VersionOptions.Latest, GetContentTypeNames().ToArray()).List();
foreach (var contentItem in contentItems)
{
// The display url of contentItem
}
...
}
}
如何獲取ContentItem顯示網址?
啊,太簡單了,謝謝! – Tst