I have read these posts
https://our.umbraco.org/forum/templates-partial-views-and-macros/85993-archetype-mediapicker-udi
http://www.codeshare.co.uk/blog/how-to-get-the-file-path-of-a-media-item-in-umbraco/
but I'm still unable to get the value from the media picker.
On my last attempt, I got the following error.
Object reference not set to an instance of an object
If I try the following:
string img = "";
foreach (var d in archtypePanel.Properties)
{
if (d.Alias == "imageToDisplay")
{
img = d.Value.ToString();
}
}
I can see the media UDI: "umb://media/15cc14d318f3444a86ab3bc7fc5787ad" but I'm unable to get any further.
I have now run into a wall, so any help on solving this issue will be helpful.
My last attempt is below:
Guid idValue = new Guid(id);
var blogPosts = CurrentPage;
IPublishedContent blogPosts2 = CurrentPage;
var archtypePanel = blogPosts2.GetPropertyValue<ArchetypeModel>("blogArchetypes").First(x=>x.Id == idValue);
ArchetypeWithTextAndImageModel model = new ArchetypeWithTextAndImageModel
{
TextContent = new HtmlString(archtypePanel.GetValue("textRichTextEditor")),
ImageId = archtypePanel.GetValue<IEnumerable<IPublishedContent>>("imageToDisplay").ToString()// imgUrl
};
But ImageId throws the error.