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
What is the recommended approach for writing a conditional statement with a property alias? For example, if you have a text string property alias called propertyAlias and you want to do nothing if the property alias has no text, but do something else if the property alias has text, what would be the approach?
An IPublishedContent item has a 'HasValue' method that you can check first before doing something with the property value:
<!-- don't do anything here, no title has been entered -->
is that what you are after?
I think so. I will get back to you to mark this as the solution if it works. Just implementing now.
Hi, Marc, was there a reason you didn't use @Model.Value("string") instead of @(Model.Value
Yes, largely out of habit
if you write
You are requesting a 'strongly typed version' of the property, in this case a string... but if it were a 'Media Picker'
you would get back an IPublishedContent object representing the picked media
if it was a multimedia picker... basically something called a PropertyValueConverter in the core of Umbraco (you can write your own too for custom property editor types) is doing the conversion from the stored value to something nice to work with in your view.
When you just use
then the type returned is 'object' - if all you are doing is writing it out directly into the View, then there is no difference between
but if you are assigning the value to a variable to manipulate it further, or you have a complex type (eg the media picker scenario) then the 'strongly typed' approach can save effort...
... why the extra brackets?
well because the strongly typed <string> bit looks like a html tag.. it can confuse the razor view syntax checker, putting it inside a @() just tells the parser that this is code, and not html...
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted