C# Umbraco-c中的DocumentType字段#

C# Umbraco-c中的DocumentType字段#,c#,umbraco,C#,Umbraco,我想在c#中得到一个Umbraco字段,如下所示: (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

我想在c#中得到一个Umbraco字段,如下所示:

(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.
我不知道这个错误以及如何解决它


谢谢

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

..
using Umbraco.Web;
..

var idPage = 1234; // you should get this dynamically :)
IPublishedContent page = Umbraco.TypedContent(idPage);
var labelFailure = page.GetPropertyValue<string>("labelFailure");
。。
使用Umbraco.Web;
..
var idPage=1234;//您应该动态地获取此信息:)
IPPublishedContent页面=Umbraco.TypedContent(idPage);
var labelFailure=page.GetPropertyValue(“labelFailure”);

您是否试图访问自定义c#code中的Umbraco.Field而不在视图中?是的,我想创建一个ViewData。