The issue you are getting is because a Content Picker returns an IPublishedContent, not the explicit type of the picked content node.
What you can do is the following:
@if(author is Author typedAuthor)
{
<p>@typedAuthor.AuthorName</p>
}
or
<p>@author.Value("authorName")</p>
The first option checks that what you are trying to access is of type Author and then stores it in a strongly typed variable typedAuthor so you can then access it how you were trying to. The second is falling back to accessing properties off of the IPublishedContent interface.
Content Picker Issue
Hi all,
I want pick a author on my Blog Post page, so, I create a Content Picker for this, Document type like this:
and now, I can pick a person normally:
but when I follow this page to get the person, code like this:
then, I got a Compilation Error:
Does anyone know, which step is wrong?
Best regards
Cary
FYI Author document type
Hi Cary,
The issue you are getting is because a Content Picker returns an IPublishedContent, not the explicit type of the picked content node.
What you can do is the following:
or
The first option checks that what you are trying to access is of type Author and then stores it in a strongly typed variable
typedAuthor
so you can then access it how you were trying to. The second is falling back to accessing properties off of the IPublishedContent interface.Hope that helps
Nik
Hi, Nik
Second way take effect! thanks a lot.
Cary
First one take effect in my local env, but give me a compiler error on my online env...
is working on a reply...