[英]Umbraco - DocumentType Field in c#
I'm trying to get an Umbraco Field in c# like this : 我试图在c#中获得一个Umbraco Field,如下所示:
(String.Format(Umbraco.Field("labelFailure").ToString(), username));
But I'm getting the following error : 但是我收到以下错误:
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. 我不知道错误以及如何解决它。
Thanks! 谢谢!
If you are not in a view you should use GetPropertyValue on the IPublishedContent of the page to get your value: 如果您不在视图中,则应在页面的IPublishedContent上使用GetPropertyValue来获取您的值:
..
using Umbraco.Web;
..
var idPage = 1234; // you should get this dynamically :)
IPublishedContent page = Umbraco.TypedContent(idPage);
var labelFailure = page.GetPropertyValue<string>("labelFailure");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.