So i'm trying to add items to a page. Now the size of these items can be configured in the backend with a dropdown(Small, Medium or Large). I'm trying to read the property using GetPropertyValue("alias"). Now to compare this I made a simple if statement.
var image = Umbraco.TypedMedia(child.GetPropertyValue("itemImage"));
var size = child.GetPropertyValue("itemSize").ToString();
if (size == "Large")
{
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
</div>
}
Now the problem is, if i convert the value to a string it gives me the following error: Object reference not set to an instance of an object.
The weird thing is that the object I'm trying to convert is not null at all and using visual studio i can see it has that exact value.
When i'm not converting it is has the correct value, but for some reason the if statement says it's not the same value and just goes on without executing the stuff within the if statement.
Happy to help - let me know if you need more help getting the item image to come through.
Also just on your point about VS, I've noticed that in view files specifically, it often gets the line number wrong on null instances. It's one of VS's many quirks.
GetPropertyValue("").ToString() error
So i'm trying to add items to a page. Now the size of these items can be configured in the backend with a dropdown(Small, Medium or Large). I'm trying to read the property using GetPropertyValue("alias"). Now to compare this I made a simple if statement.
Now the problem is, if i convert the value to a string it gives me the following error: Object reference not set to an instance of an object.
The weird thing is that the object I'm trying to convert is not null at all and using visual studio i can see it has that exact value.
When i'm not converting it is has the correct value, but for some reason the if statement says it's not the same value and just goes on without executing the stuff within the if statement.
Not 100% confident about this one but try:
Also, are you sure that
child.GetPropertyValue("itemImage")
is returning something?Yeah you're right.
it is null indeed, for some reason Visual Studio kept saying the error was in the line above..
Thanks!
Happy to help - let me know if you need more help getting the item image to come through.
Also just on your point about VS, I've noticed that in view files specifically, it often gets the line number wrong on null instances. It's one of VS's many quirks.
is working on a reply...