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
Umbraco 10.1.0
Am I missing something simple here? The first if doesn't work but the second one does on this textBox property.
@if (Model.HasValue(Model.WelcomeBoxTitle)) { <h1>@Model.WelcomeBoxTitle (1)</h1> } @if (Model.HasValue("welcomeBoxTitle")) { <h1>@Model.WelcomeBoxTitle (2)</h1> }
the second one is correct since the HasValue is to check if the property exists on the IPublishedContent and expects the property alias
Ah I see.
Is there a way then to check if a property has content using the models builder version?
HasValue will return false if the property itself is empty.
sorry for confusion, my first comment was not 100% accurate.
so @if (Model.HasValue("welcomeBoxTitle")) will be false if the property does not exist or is empty
@if (Model.HasValue("welcomeBoxTitle"))
Yes, that one works for me, but this one always returns false regardless i.e if there is content in the property or not.
@if (Model.HasValue(Model.WelcomeBoxTitle)) { <h1>@Model.WelcomeBoxTitle (1)</h1> }
That is because Model.WelcomeBoxTitle is not the property alias, and hasvalue requires the property alias
Model.WelcomeBoxTitle
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Model.HasValue
Umbraco 10.1.0
Am I missing something simple here? The first if doesn't work but the second one does on this textBox property.
the second one is correct since the HasValue is to check if the property exists on the IPublishedContent and expects the property alias
Ah I see.
Is there a way then to check if a property has content using the models builder version?
HasValue will return false if the property itself is empty.
sorry for confusion, my first comment was not 100% accurate.
so
@if (Model.HasValue("welcomeBoxTitle"))
will be false if the property does not exist or is emptyYes, that one works for me, but this one always returns false regardless i.e if there is content in the property or not.
That is because
Model.WelcomeBoxTitle
is not the property alias, and hasvalue requires the property aliasis working on a reply...