问题
I'm trying to get an Umbraco Field in c# like this :
(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!
回答1:
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");
来源:https://stackoverflow.com/questions/44655299/umbraco-documenttype-field-in-c-sharp