Umbraco - C# 中的 DocumentType 字段 [英] Umbraco - DocumentType Field in c#

查看:24
本文介绍了Umbraco - C# 中的 DocumentType 字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试像这样在 c# 中获得一个 Umbraco 字段:

I'm trying to get an Umbraco Field in c# like this :

(String.Format(Umbraco.Field("labelFailure").ToString(), username));

但我收到以下错误:

Cannot return the IPublishedContent because the UmbracoHelper was constructed with an UmbracoContext and the current request is not a front-end 
request.

我不知道错误以及如何解决它.

I don't know the error and how to resolve it.

谢谢!

推荐答案

如果您不在视图中,则应在页面的 IPublishedContent 上使用 GetPropertyValue 来获取您的值:

If you are not in a view you should use GetPropertyValue on the IPublishedContent of the page to get your value:

..
using Umbraco.Web;
..

var idPage = 1234; // you should get this dynamically :)
IPublishedContent page = Umbraco.TypedContent(idPage);
var labelFailure = page.GetPropertyValue<string>("labelFailure");

这篇关于Umbraco - C# 中的 DocumentType 字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆