Copied to clipboard

Flag this post as spam?

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


  • andrew shearer 506 posts 653 karma points
    Aug 17, 2020 @ 05:41
    andrew shearer
    0

    Modelsbuilder: still possible to get IPublishedContent somehow?

    hello - the Modelsbuilder docs say:

    In other words, when using the Models Builder, the content cache does not return IPublishedContent objects anymore, but strongly typed models.

    that's great for views and all, but is there still a way to get the original IPC and not a strongly typed model? "Umbraco.Content(id)" doesn't seem to have an overload, is there another way?

    I am introducing/converting my project to Modelsbuilders but i have some existing controller code that would be easier to leave as-is dealing in IPCs.

    thanks

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Aug 17, 2020 @ 07:29
    Nik
    0

    Hi Andrew,

    If you have the strongly typed model, you can convert it to IPublishedContent explicitly with a cast, however if your model is, for example, a nested content object, then it's not an IPublishedContent, but instead an IPublishedElement. The Models Builder models implement either of these classes (I don't think they implement both).

    Also, Umbraco.Content returns IPublishedContent I believe, but if you look at it in the Visual Studio Watch Window, you will also see that it is the strongly typed model.

    Cheers,

    Nik

  • andrew shearer 506 posts 653 karma points
    Aug 21, 2020 @ 00:11
    andrew shearer
    0

    thanks for the info Nik :)

Please Sign in or register to post replies

Write your reply to:

Draft