Umbraco - C# 中的文档类型字段
Umbraco - DocumentType Field in c#
我正在尝试像这样在 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.
我不知道错误以及如何解决它。
谢谢!
如果您不在视图中,您应该在页面的 IPublishedContent 上使用 GetPropertyValue 来获取您的值:
..
using Umbraco.Web;
..
var idPage = 1234; // you should get this dynamically :)
IPublishedContent page = Umbraco.TypedContent(idPage);
var labelFailure = page.GetPropertyValue<string>("labelFailure");
我正在尝试像这样在 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.
我不知道错误以及如何解决它。
谢谢!
如果您不在视图中,您应该在页面的 IPublishedContent 上使用 GetPropertyValue 来获取您的值:
..
using Umbraco.Web;
..
var idPage = 1234; // you should get this dynamically :)
IPublishedContent page = Umbraco.TypedContent(idPage);
var labelFailure = page.GetPropertyValue<string>("labelFailure");