Copied to clipboard

Flag this post as spam?

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


  • ced 16 posts 136 karma points
    Apr 05, 2023 @ 08:06
    ced
    0

    Umbraco 11 - Model.Value - No ModelsBuilder

    Hi everyone

    I'm under Umbraco 11.

    I want to access documentType's property value without using the models builder.

    According to documentation https://docs.umbraco.com/umbraco-cms/fundamentals/design/rendering-content/, it's Model.Value("alias") but it's not.

    First argument of "Value()" method requires an IPublishedValueFallback. How could I get my property value, what kind of argument should I pass to the method ?

  • Huw Reddick 1932 posts 6722 karma points MVP 3x c-trib
    Apr 05, 2023 @ 08:55
    Huw Reddick
    0

    Does your view have @inherits UmbracoViewPage

    Model.Value("alias") does not require a fallback

  • ced 16 posts 136 karma points
    Apr 05, 2023 @ 09:57
    ced
    0

    From a view this is working indeed.

    But it's not what I try to achieve. Let me reformulate my question: how could I get the property value of a documentType outside a view?

    To explain what I want. I want to deal documentType's data with my own models because somewhere in my code I don't want Umbraco to be referenced. This means I have to "map" IPublishedContent to my models using Model.Value(...).

    Is this possible without providing an IPublishedValueFallback ?

  • Huw Reddick 1932 posts 6722 karma points MVP 3x c-trib
    Apr 05, 2023 @ 12:03
    Huw Reddick
    0

    You should probably use the IPublishedContentQuery to get your content

    https://docs.umbraco.com/umbraco-cms/implementation/services

  • ced 16 posts 136 karma points
    Apr 05, 2023 @ 12:52
    ced
    0

    Thanks for your responses.

    Of course I'm already using IPublishedContentQuery. And still it gives me an IPublishedContent I want to map with a model of my own.

    But nevermind... I already found a solution... using ModelsBuilder even if I didn't want to... (opportunity knocks) :-)

  • Huw Reddick 1932 posts 6722 karma points MVP 3x c-trib
    Apr 05, 2023 @ 13:03
    Huw Reddick
    1

    Umbraco does not know anything about your models, only IPublishedContent (unless you use modelsbulder to give you strongly typed content)

    You could try this approach

    https://our.umbraco.com/forum/using-umbraco-and-getting-started/107323-using-iumbracomapper-to-map-custom-models-or-automapper

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies