2017-08-01 66 views
0

我最近升級到7.6.3,並且在檢視視圖中的媒體圖像URL時出現問題。爲了測試purpposes,我添加了一個新的MediaPicker2屬性的一個節點,建立一個價值,並試圖在我的Razor視圖來獲得它的值:升級後無法從Umbraco獲取媒體圖像URL

var icon2 = Model.Content.GetProperty("icon2"); 

的對象則是這樣的: enter image description here

執行Model.Content.GetPropertyValue("icon2")引發以下錯誤:

An exception of type 'System.Exception' occurred in Umbraco.Core.dll but was not handled in user code

Additional information: Exception while creating a value.

InnerException: "Object reference not set to an instance of an object."

Model.Content.GetPropertyValue<IPublishedContent>("icon2")拋出了同樣的錯誤。

我在做什麼錯?

+0

在umbracoSettings.config被EnablePropertyValueConverters設爲錯誤還是真的? – Eyescream

+0

它設置爲true。 – SsjCosty

+0

你升級了哪種版本的Umbraco? – Harvey

回答

0

根據this answer,你所做的是正確的。但是,我不確定它爲什麼不起作用。

不過,我已經回答過類似的問題這一點,並I found a roundabout way of getting the node for a Udi

您可以從圖像的字符串使用此代碼得到一個IPublishedContent:

// Your string. 
var imageString = Model.Content.GetPropertyValue<string>("icon2"); 

// Get the guid from this string. 
var imageGuidUdi = GuidUdi.Parse(imageString); 

// Get the ID of the node! 
var imageNodeId = ApplicationContext.Current.Services.EntityService.GetIdForKey(guidUdi.Guid, (UmbracoObjectTypes)Enum.Parse(typeof(UmbracoObjectTypes), guidUdi.EntityType, true)); 

// Finally, get the node. 
var imageNode = Umbraco.TypedMedia(imageNodeId.Result);