I'm new to Umbraco and tried to find my answer by browsing the forum but no luck so sorry if it's a duplicate question ...
So my issue is that i've uploaded some pictures to my Media folder ( both root and sub-folders) but now when I want to access them in my view , they come as null aka no pictures ..
I've tried different ways like :
var test = Model.Content.GetPropertyValue<IPublishedContent>("newsImage");
or
var mediaId = Model.Content.GetPropertyValue<string>("newsImage");
still it comes null. If i hardcode the id , It'll return my picture but I want to do it dynamically .. any tips ?
As you're trying to get the image from a property on a content item, I'm assuming this content item has a media/image picker. What type is that picker?
If you're using the default media picker, I think the value type will be IEnumerable<IPublishedContent> (a list of images) rather than just IPublishedContent:
var test = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("newsImage");
Alternatively you can write out the type of the property value:
object test = Model.Content.GetPropertyValue("newsImage");
string type = test == null ? "NULL" : test.GetType() + "";
type will either contain the value type, or NULL, but then something else is probably wrong.
I guess I made myself a bit of inception here ... I'm trying to access the child picture on the parent view which will (obviously) return null. Problem is that I've changed the "Alias" to see if I can access the child but not luck yet.
but on parent lvl this piece of code works just fine:
Media picker returning null
Hey folks,
I'm new to Umbraco and tried to find my answer by browsing the forum but no luck so sorry if it's a duplicate question ...
So my issue is that i've uploaded some pictures to my Media folder ( both root and sub-folders) but now when I want to access them in my view , they come as null aka no pictures ..
I've tried different ways like :
or
still it comes null. If i hardcode the id , It'll return my picture but I want to do it dynamically .. any tips ?
cheers
Hi Mike,
As you're trying to get the image from a property on a content item, I'm assuming this content item has a media/image picker. What type is that picker?
If you're using the default media picker, I think the value type will be
IEnumerable<IPublishedContent>
(a list of images) rather than justIPublishedContent
:Alternatively you can write out the type of the property value:
type
will either contain the value type, orNULL
, but then something else is probably wrong.Hey Anders,
I guess I made myself a bit of inception here ... I'm trying to access the child picture on the parent view which will (obviously) return null. Problem is that I've changed the "Alias" to see if I can access the child but not luck yet.
but on parent lvl this piece of code works just fine:
Cheers
is working on a reply...