Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Cary 21 posts 107 karma points
    Dec 23, 2020 @ 08:05
    Cary
    0

    Hi all,

    I want pick a author on my Blog Post page, so, I create a Content Picker for this, Document type like this:

    enter image description here

    and now, I can pick a person normally:

    enter image description here

    but when I follow this page to get the person, code like this:

    enter image description here

    then, I got a Compilation Error:

    enter image description here

    Does anyone know, which step is wrong?

    Best regards

    Cary

  • Cary 21 posts 107 karma points
    Dec 23, 2020 @ 08:06
    Cary
    0

    FYI Author document type

    enter image description here

  • Nik 1598 posts 7177 karma points MVP 6x c-trib
    Dec 23, 2020 @ 08:46
    Nik
    100

    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:

    @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.

    Hope that helps

    Nik

  • Cary 21 posts 107 karma points
    Dec 23, 2020 @ 08:58
    Cary
    0

    Hi, Nik

    Second way take effect! thanks a lot.

    Cary

  • Cary 21 posts 107 karma points
    Dec 23, 2020 @ 09:01
    Cary
    0

    First one take effect in my local env, but give me a compiler error on my online env...

Please Sign in or register to post replies

Write your reply to:

Draft