Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I'm working on my first Umbraco MVC project, so it's all a bit new to me.
In my Partial View Macro, I try to check if a value for a property is set like this:
@if(!Model.Content.IsNull("memberEmail"))
{
<li>
<i class="icon-envelope-alt"></i>
<a href="mailto:@Model.Content.GetPropertyValue("memberEmail")">@Model.Content.GetPropertyValue("memberEmail")</a>
</li>
}
But this is not working, I'm getting an invalid cast error.
I checked the v6 Razor Cheatsheet and it gives this method for property checking:
.IsNull(string PropertyAlias)
So I'm not sure why the above code is not working.
Thanks for your help,
Anthony
Hi Anthony,
You should use HasValue, e.g
@if(Model.Content.HasValue("memberEmail"))
Thanks,
Jeavon
Hi Jeavon,
Thanks a lot, that's pretty simple. I previously tried the HasPropery() method, but that hadn't the result I was looking for, as that method only checks if a doctype has a the given property, not if it's empty.
greetings,
No worries, if you want to be really safe you can do
@if(Model.Content.HasProperty("memberEmail") && Model.Content.HasValue("memberEmail"))
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
checking for empty property in v6 Razor
Hi,
I'm working on my first Umbraco MVC project, so it's all a bit new to me.
In my Partial View Macro, I try to check if a value for a property is set like this:
@if(!Model.Content.IsNull("memberEmail"))
{
<li>
<i class="icon-envelope-alt"></i>
<a href="mailto:@Model.Content.GetPropertyValue("memberEmail")">@Model.Content.GetPropertyValue("memberEmail")</a>
</li>
}
But this is not working, I'm getting an invalid cast error.
I checked the v6 Razor Cheatsheet and it gives this method for property checking:
.IsNull(string PropertyAlias)
So I'm not sure why the above code is not working.
Thanks for your help,
Anthony
Hi Anthony,
You should use HasValue, e.g
Thanks,
Jeavon
Hi Jeavon,
Thanks a lot, that's pretty simple. I previously tried the HasPropery() method, but that hadn't the result I was looking for, as that method only checks if a doctype has a the given property, not if it's empty.
greetings,
Anthony
Hi Anthony,
No worries, if you want to be really safe you can do
Thanks,
Jeavon
is working on a reply...