Umbraco:Razor语法中的Item标签

时间:2014-08-06 12:33:33

标签: c# asp.net-mvc razor umbraco

使用主模板,我们的想法是能够从Umbraco中提取元标记和描述。最初主模板页面使用的是WebForms,但整个项目已经转换为Razor页面。因此,使用以下内容从Umbraco中提取元标记和描述:

<umbraco:Item field="MetaKeywords" insertTextBefore="&lt;meta name=&quot;keywords&quot; content=&quot;" insertTextAfter="&quot; /&gt;" runat="server"></umbraco:Item>
<umbraco:Item field="MetaDescription" insertTextBefore="&lt;meta name=&quot;Description&quot; content=&quot;" insertTextAfter="&quot; /&gt;" runat="server"></umbraco:Item>

然而,在做了一些阅读之后(如果我错了,请纠正我)umbraco item标签不能与剃刀语法一起使用。我不是专家,我对Umbraco等了解得很清楚。有没有办法可以使用剃刀页面执行相同的功能?在使用上面的代码时,Visual studio会说umbraco标签是一个无法识别的命名空间。

这是一个MVC项目,如果它提供任何进一步的复杂性/信息。在此先感谢,任何帮助将不胜感激。

3 个答案:

答案 0 :(得分:2)

旧帖子,但我想添加我为MVC找到的解决方案

https://our.umbraco.org/forum/using/ui-questions/22198-Meta-Tags

这个旧解决方案不适合您的原因是,它适用于以WebForms模式运行的网站。由于您使用的是Umbraco 7.2.2,因此它使用MVC作为默认值,

在MVC模板中,你可以像这样调用它。

@Umbraco.Field("AliasOfTheField")

https://our.umbraco.org/Documentation/Reference/Mvc/views#RenderingafieldwithUmbracoHelper

因此对于元描述和元关键字,它看起来像这样。

@Umbraco.Field("metaDescription")
@Umbraco.Field("metaKeywords")

答案 1 :(得分:1)

我已经设法让它现在起作用。对于将来遇到此问题的任何其他人来说,这就是我如何使用它。我检查了当前页面是否具有我正在查看的属性,然后根据该属性分配了关键字和描述。

 @if (CurrentPage.HasProperty("SeoKeywords") && CurrentPage.HasProperty("SeoDescription"))
    {
        <meta name="keywords" content="@CurrentPage.SeoKeywords" />
        <meta name="description" content="@CurrentPage.SeoDescription" />
    }

在Umbraco上,我正在使用的基页文档类型具有关键字和描述的属性,每个属性都带有别名。这个别名是我检查CurrentPage.HasProperty(&#34;&#34;)的原因。

现在这对我有用。希望这可能有助于为其他人提供一些帮助。 还要感谢&#39; Exception&#39;澄清原始问题。

答案 2 :(得分:0)

在简单的剃须刀引擎中不支持Umbraco标签(直到现在,如您的问题所示)

基于

的Web应用程序,您必须在asp.net mvc中使用htmlhelpers或html标记。

代表: -

@Html.TextBoxFor(),@Html.TextArea()

...或仅限简单的html标签..