Umbraco - c#中的DocumentType字段

时间:2017-06-20 14:04:04

标签: c# umbraco

我正试图在c#中获得一个Umbraco Field:

(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.

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

谢谢!

1 个答案:

答案 0 :(得分:3)

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

..
using Umbraco.Web;
..

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