Copied to clipboard

Flag this post as spam?

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


  • Jamie Attwood 207 posts 501 karma points c-trib
    Sep 07, 2016 @ 17:41
    Jamie Attwood
    1

    Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'Content'

    Hope someone can please help with this confusing error:

    I have a template calling a partial view:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Base.cshtml";
    }
    
    @Html.Partial("FinancialReports", Model.Content)
    

    Then my partial view:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedContent>
    
    @{
        var pageName = Model.Content.Name;
        var childPages = Model.Content.Children;
    }
    
    <h1>@pageName</h1>
    

    When this is run I keep getting the error:

    Compiler Error Message: CS1061: 'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'Content' and no extension method 'Content' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found (are you missing a using directive or an assembly reference?)

    The documentation on this is really vague. https://our.umbraco.org/documentation/Reference/Querying/IPublishedContent/

    My goal is to create a strongly typed partial view that I can use linq queries on...

    Thanks in advance,

    Jamie

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Sep 07, 2016 @ 21:24
    Alex Skrypnyk
    0

    Hi Jamie,

    Are you trying to pass to partial view current page?

    You don't need to do it, all pages has Current page.

    Example how it should work:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    
    @{
        var pageName = Umbraco.AssignedContentItem.Name;
        var childPages = Umbraco.AssignedContentItem.Children;
    }
    
    <h1>@pageName</h1>
    

    Hope it will help.

    Thanks,

    Alex

  • Jamie Attwood 207 posts 501 karma points c-trib
    Sep 08, 2016 @ 21:24
    Jamie Attwood
    1

    Thanks Alex - I guess I am just really confused with the documentation. There are snippits of code everywhere, but they are all missing the @inherits statements and no real cohesive examples. I have seen a lot of blog posts on the subject.

    This section needs a major overhaul: https://our.umbraco.org/documentation/Reference/Querying/IPublishedContent/

    I appreciate your feedback! Thank-you!

    Jamie

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Sep 09, 2016 @ 08:15
    Alex Skrypnyk
    0

    You are welcome, Jamie.

    Did you solve the problem?

    Write all your questions on this firum, this is the best community!

    Thanks,

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft