2017-08-01 3 views
0

最近7.6.3にアップグレードしましたが、私のビューでメディアイメージのURLを取得する際に問題が発生しています。 purpposesをテストするために、私はそれに値を設定し、いずれかのノードのための新しいMediaPicker2プロパティを追加し、私のかみそりビューでその値を取得しようとしました:アップグレード後に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

がEnablePropertyValueConvertersがに設定されています偽か真か? – Eyescream

+0

これはtrueに設定されています。 – SsjCosty

+0

Umbracoのどのバージョンからアップグレードしましたか? – Harvey

答えて

0

this answerによれば、あなたがしていることは正しいです。しかし、なぜそれが動作していないのか分かりません。

しかし、私は前にこれに類似した質問に答え、そしてI found a roundabout way of getting the node for a Udiている:あなたはこのコードを使用して、画像列からIPublishedContentを得ることができます

:umbracoSettings.configで

// 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); 
関連する問題