EPiServer - 对 ContentReference 属性 的 "Content" 的 href?
EPiServer - href to "Content" of a ContentReference property?
向所有 EPiServer 大师致敬。
环境:EPiServer 7.
问题描述:
我有一个具有不同属性的 PageType。其中一个属性是 ContentReference。
[CultureSpecific]
[Display(
Name = "Specific documents",
GroupName = SystemTabNames.Content,
Order = 1)]
public virtual ContentReference SpecificDocument { get; set; }
在我看来,我根据 属性 SpecificDocument 是否为空向不同的操作显示一个图标 link。 ContentReference 属性 应该包含一个文件,例如 PDF。
@model IPageViewModel<SpacePage>
<div class="row">
@if (Model.CurrentPage.SpecificDocument != null)
{
<a class="image" href="#"> </a>
}
else
{
<a class="icon" href="some action if the property is empty"></a>
}
</div>
我的问题:
如果 SpecificDocument 属性 不为空,我如何 href 到 中的特定 Content ]ContentReference 属性?
说明: 当用户单击该图标时,它会在 window 中打开特定文档 (PDF) 或下载它。
请记住,我是 EPiServer 开发的新手。
此致,
克里斯
您可以使用 UrlResolver.Current 获取内容引用的 URL:
var url = UrlResolver.Current.GetUrl(CurrentPage.SpecificDocument)
一些关于不同 URL 可用的深入信息:http://world.episerver.com/blogs/Linus-Ekstrom/Dates/2014/2/The-three-rendering-modes-of-EPiServer/
此外,您可能希望使用 ContentReference.IsNullOrEmpty 而不是仅对 属性 进行空值检查,以确保 属性 已设置.
向所有 EPiServer 大师致敬。
环境:EPiServer 7.
问题描述:
我有一个具有不同属性的 PageType。其中一个属性是 ContentReference。
[CultureSpecific]
[Display(
Name = "Specific documents",
GroupName = SystemTabNames.Content,
Order = 1)]
public virtual ContentReference SpecificDocument { get; set; }
在我看来,我根据 属性 SpecificDocument 是否为空向不同的操作显示一个图标 link。 ContentReference 属性 应该包含一个文件,例如 PDF。
@model IPageViewModel<SpacePage>
<div class="row">
@if (Model.CurrentPage.SpecificDocument != null)
{
<a class="image" href="#"> </a>
}
else
{
<a class="icon" href="some action if the property is empty"></a>
}
</div>
我的问题:
如果 SpecificDocument 属性 不为空,我如何 href 到 中的特定 Content ]ContentReference 属性?
说明: 当用户单击该图标时,它会在 window 中打开特定文档 (PDF) 或下载它。
请记住,我是 EPiServer 开发的新手。
此致, 克里斯
您可以使用 UrlResolver.Current 获取内容引用的 URL:
var url = UrlResolver.Current.GetUrl(CurrentPage.SpecificDocument)
一些关于不同 URL 可用的深入信息:http://world.episerver.com/blogs/Linus-Ekstrom/Dates/2014/2/The-three-rendering-modes-of-EPiServer/
此外,您可能希望使用 ContentReference.IsNullOrEmpty 而不是仅对 属性 进行空值检查,以确保 属性 已设置.