Umbraco - DocumentType Field in c#

≯℡__Kan透↙ 提交于 2020-02-05 03:50:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!