Orchardcms 获取Orchard中备用形状cshtml文件中分类法字段的url

Orchardcms 获取Orchard中备用形状cshtml文件中分类法字段的url,orchardcms,taxonomy,Orchardcms,Taxonomy,我使用Orchard 1.10.1。我有一个CustomContentType,它有一个“组”分类字段。在Content CustomContentType.Detail.cshtmlalternate中,我想有一个指向某个分类术语的链接。这是我的代码: <a href='???'>@Model.ContentItem.CustomContentType.Group.Terms[0].Name</a> 如何获取url以替换上述代码中的此?” 提前感谢。您有几个选择。

我使用
Orchard 1.10.1
。我有一个
CustomContentType
,它有一个“组”
分类字段
。在
Content CustomContentType.Detail.cshtml
alternate中,我想有一个指向某个分类术语的链接。这是我的代码:

<a href='???'>@Model.ContentItem.CustomContentType.Group.Terms[0].Name</a>

如何获取url以替换上述代码中的此
?”


提前感谢。

您有几个选择。我刚刚将它们直接输入浏览器,Orchard是一个很难驾驭其模型的野兽,因此如果它们在你脸上爆炸,请让我知道,我会深入挖掘:)

让orchard创建整个链接 查看
TaxonomyItemLink.cshtml
文件,您可以看到链接如下所示:

@using Orchard.Taxonomies.Models
@{
    TermPart part = Model.ContentPart;
}
@Html.ItemDisplayLink(part)
因此,在您的情况下,您可以使用:

@Html.ItemDisplayLink((ContentPart)Model.ContentItem.CustomContentType.Group.Terms[0])
只需获取URL即可 您可以使用
@Url.ItemDisplayUrl()
将可路由内容项转换为Url

<a href="@Url.ItemDisplayUrl((ContentPart)Model.ContentItem.CustomContentType.Group.Terms[0])">
  @Model.ContentItem.CustomContentType.Group.Terms[0].Name
</a>

我不确定slug是否只包含结束位或其完整url。

您有一些选项可供选择。我刚刚将它们直接输入浏览器,Orchard是一个很难驾驭其模型的野兽,因此如果它们在你脸上爆炸,请让我知道,我会深入挖掘:)

让orchard创建整个链接 查看
TaxonomyItemLink.cshtml
文件,您可以看到链接如下所示:

@using Orchard.Taxonomies.Models
@{
    TermPart part = Model.ContentPart;
}
@Html.ItemDisplayLink(part)
因此,在您的情况下,您可以使用:

@Html.ItemDisplayLink((ContentPart)Model.ContentItem.CustomContentType.Group.Terms[0])
只需获取URL即可 您可以使用
@Url.ItemDisplayUrl()
将可路由内容项转换为Url

<a href="@Url.ItemDisplayUrl((ContentPart)Model.ContentItem.CustomContentType.Group.Terms[0])">
  @Model.ContentItem.CustomContentType.Group.Terms[0].Name
</a>

我不确定slug是否只包含结尾位或其完整url。

谢谢您的回答,它工作得非常好。我使用了“justgettheurl”,但我用“ContentPart”替换了“TermPart”。我还测试了“Just get the Slug”,术语[0]。Slug只包含相对url。哦,很好:)我的果园技能正在提高。我想我已经看到它将其投射到
IContent
,这样你就不必担心你正在处理的具体类型是什么。我更新了答案,这样下次复制/粘贴时就不会被发现了。你是最好的:)谢谢你的回答,它工作得很好。我使用了“justgettheurl”,但我用“ContentPart”替换了“TermPart”。我还测试了“Just get the Slug”,术语[0]。Slug只包含相对url。哦,很好:)我的果园技能正在提高。我想我已经看到它将其投射到
IContent
,因此您实际上不需要担心您正在处理的特定类型是什么。我更新了答案,以便下次复制/粘贴时不会被发现您是最好的:)