Alex Caron Alex Caron - 1 year ago 59
C# Question

Umbraco - DocumentType Field in c#

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

I don't know the error and how to resolve it.


Answer Source

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");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download