@Francisco: You're right, Model.visual (where "visual" is of type Media Picker) is not a string/integer, so it shouldn't be a valid parameter for the MediaById() method, but for some reason it works fine without the if-statement. Oh well, the GetProperty().Value approach works in both cases, so I'm happy. :)
@Fuji: This is not true, if (Model.HasValue() { ... } works just fine, because we're already inside a @{ ... } statement.
Null reference error inside "if (HasValue) { }" statement?
Can anyone explain why I'm getting a "Cannot perform runtime binding on a null reference" on this code:
On the @image.Id call to be exact.
But when I leave out the HasValue-check it works fine (I'm getting the same id twice, as expected):
!?!?!?
I'm using Umbraco 4.11.5
Hi Arjan
Ran into this in V6 and am using DAMP, overcame it with
if (String.IsNullOrEmpty(Model.Visual.PropertyData)) ;
This may not be exact for you, but you need to check against the string for an image.(you may need UmbracoFile??)
As I say, this may not be a 100% answer, but will hopefully point you in the right direction.
Regards G
I'm still not sure what caused the issue, but this fixed it for me:
I believe Model.visual is not of type integer (required by .MediaById()).
However, If you say that removing the condition, it works...
Hi Arjan,
You are missing a @ sign in your code
@Francisco: You're right, Model.visual (where "visual" is of type Media Picker) is not a string/integer, so it shouldn't be a valid parameter for the MediaById() method, but for some reason it works fine without the if-statement. Oh well, the GetProperty().Value approach works in both cases, so I'm happy. :)
@Fuji: This is not true,
if (Model.HasValue() { ... }
works just fine, because we're already inside a@{ ... }
statement.Truue my bad!! :)
is working on a reply...