Copied to clipboard

Flag this post as spam?

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


  • David Amri 214 posts 740 karma points
    Nov 14, 2018 @ 16:29
    David Amri
    0

    Model.Content IPublishedContent does not contain a definition for "Content"

    Hi, why am I not able to access "Content", am I missing a reference?

    In my view:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
        Layout = "kund_unikum_master_t.cshtml";
    
        var currentPage = Model.Content;
    }
    

    I get the error

    "IPublishedContent does not contain a definition for 'Content' and no extension method 'Content' accepting a first argument of type 'IpublishedContent' could be found (are you missing a suign directive or an assembly reference?)"

    Best regards /David

  • Nik 1617 posts 7263 karma points MVP 7x c-trib
    Nov 14, 2018 @ 16:41
    Nik
    101

    Hi David,

    Quick answer:

    If you are inheriting from UmbracoViewPage, you don't need .Content to access the Model properly. This is only required if you are inheriting from UmbracoTemplatePage.

    Extended answer

    UmbracoTemplatePage requires a RenderModel to be passed to it rather than just IPublishedContent. The RenderModel has a property on it called Content which is why you need to access the actual content via Model.Content. This content property is an IPublishedContent.

    UmbracoViewPage, if you don't specify the model, expects an IPublishedContent (I believe) as it's default model. As such, you no longer need to access it via Model.Content as Model is the instance of IPublishedContent (or the type that was passed into the view).

    Hope that helps

    Nik

Please Sign in or register to post replies

Write your reply to:

Draft