Just follow up on Carl's reply - which is totally right.
The issue with the syntax of ipc.GetPropertyValue<string>("alias") within Visual Studio is that the Razor parser believes the opening angle-bracket to be HTML markup.
By wrapping the whole expression in curly-brackets, that tells Razor to parse as C#/code.
@(ipc.GetPropertyValue<string>("alias"))
...or you can use a code-block to assign to a variable and render that out.
@{
var value = Model.Content.GetPropertyValue<string>("alias")
}
<h1>@value</h1>
My code is in a block. I was just giving the most important part.
The issue is that the method is not recognised by the intelisense.
The compiler is complaining that IPUblishedContent does not contain the definition/method. But it is running correctly.
so to clarify:
Running and No Error Message
@{
ipc.GetProperty("alias").Value
}
Running But Showing Up As An Error
@{
ipc.GetPropertyValue<String>("alias")
}
I want to know which is officially the correct way to call the properties of IPublishedContent and why it would one would show as an error but run correctly??
GetPropertyValue is an extension method within the "Umbraco.Web" namespace... so if it can't find it, then you may need to add it to the top of your partial...
@using Umbraco.Web
@inherits UmbracoTemplatePage
If that doesn't work, I'm not sure why it wouldn't be picking it up :-(
Thank you for your help. Lee your reply gave me clue.
Maybe because i am using a custom page model it was not working. I have paced the Umbraco.Web at the top of the view page and now is all well.
IPublishedContent Object Values
Hi All,
If I have an object of IPublishedContent how should I get the property values?
Both of these work and run: Given: IPublishedContent ipc = Umbraco.Content(id);
However the bottom one shows as an error in the view with Visual Studio - but I am sure the Umbraco documentation uses this one.
Version is 7.2.* and 7.3.*
Best Regards, L
Both work fine.
The first would be more prone to error as GetProperty Could return null. Which would give you a null reference exception accessing Value.
Get propertyValue returning null would just not output anything in a lot of cases (all?).
the error is becasue of the typing
Will work, as will
and
Which defaults to a string value
Thanks
Carl
Thanks Carl,
I should have said this is showing as an error insisting that GetPropertyValue is not a method (or no definition) of IPublishedContent.
Regards, L
Hi Luke,
Just follow up on Carl's reply - which is totally right.
The issue with the syntax of
ipc.GetPropertyValue<string>("alias")
within Visual Studio is that the Razor parser believes the opening angle-bracket to be HTML markup.By wrapping the whole expression in curly-brackets, that tells Razor to parse as C#/code.
...or you can use a code-block to assign to a variable and render that out.
Cheers,
- Lee
Hi Guys,
My code is in a block. I was just giving the most important part.
The issue is that the method is not recognised by the intelisense.
The compiler is complaining that IPUblishedContent does not contain the definition/method. But it is running correctly.
so to clarify:
Running and No Error Message
Running But Showing Up As An Error
I want to know which is officially the correct way to call the properties of IPublishedContent and why it would one would show as an error but run correctly??
Regards, L
GetPropertyValue
is an extension method within the "Umbraco.Web" namespace... so if it can't find it, then you may need to add it to the top of your partial...If that doesn't work, I'm not sure why it wouldn't be picking it up :-(
I don't know about the error, sorry.
However.
GetPropertyValue("alias") is a shorter neat way of accessing the data in GetProperty("alias").Value
GetProperty("alias"). allows you to get more than just the value, the property type from the CMS for example.
So they both have uses depending on what you are doing.
Thanks
Hi Guys,
Thank you for your help. Lee your reply gave me clue. Maybe because i am using a custom page model it was not working. I have paced the Umbraco.Web at the top of the view page and now is all well.
Cheers gents.
Regards, L
is working on a reply...