Having a site with a BlockList property called topNotifications in the root of the content tree. I'm trying to access the blocks on all subpages.
The BlockList holds blocks called notificationElement
It is important that the blocks should be rendered using the template Partials/BlockList/topNotifications.cshtml
and not the default Partials/BlockList/Default.cshtml
In my layout Master.cshtml
var rootnode = Model.Root();
@Html.GetBlockListHtml(rootnode.TopNotifications, "topNotifications")
Compiler Error Message: CS1061: 'IPublishedContent' does not contain a definition for 'TopNotifications' and no accessible extension method 'TopNotifications' accepting a first argument of type 'IPublishedContent' could be found (are you missing a using directive or an assembly reference?)
I'm relatively new to Umbraco, so please bear with me, if there's an obvious reason for the error. 😬
Model.Root() most likely return an type of IPublishedContent. This does not have a property 'TopNotifications'. (Basically exactly what the error says, you can easily see this if you use VisualStudio's intellisense for example), however it has other properties that IPuplishedContent has (For example Name).
Your Rootnode is probably of a type of something like HomePage, which is based on IPublishedContent, but has extra properties. The code currently does not know these properties, it only knows that var rootnode = Model.Root(); returns a IPublishedContent type.
I'm not sure if you are using Modelsbuilder or not, but if you do you could cast it likes : var rootnode = (HomePage)Model.Root(); This way, the code knows its no longer of a type IPublishedContent, but of type HomePage and you can use rootnode.TopNotifications (Use the type of your root node),
Or if you do not use ModelsBuilder you could use the method like this:
Edit: Now that I read it again, you most like need use the @Html.GetBlockListHtml(Model, "TopNotifications"). I've added some explanation as to why the error says what it says.
GetBlockListHtml from Model.Root
Hi,
Having a site with a BlockList property called topNotifications in the root of the content tree. I'm trying to access the blocks on all subpages. The BlockList holds blocks called notificationElement
It is important that the blocks should be rendered using the template
Partials/BlockList/topNotifications.cshtml
and not the default
Partials/BlockList/Default.cshtml
In my layout
Master.cshtml
and in
Partials/BlockList/topNotifications.cshtml
But i'm getting an error:
I'm relatively new to Umbraco, so please bear with me, if there's an obvious reason for the error. 😬
Thanks
Hi Molu,
Model.Root() most likely return an type of IPublishedContent. This does not have a property 'TopNotifications'. (Basically exactly what the error says, you can easily see this if you use VisualStudio's intellisense for example), however it has other properties that IPuplishedContent has (For example Name).
Your Rootnode is probably of a type of something like HomePage, which is based on IPublishedContent, but has extra properties. The code currently does not know these properties, it only knows that
var rootnode = Model.Root();
returns a IPublishedContent type.I'm not sure if you are using Modelsbuilder or not, but if you do you could cast it likes :
var rootnode = (HomePage)Model.Root();
This way, the code knows its no longer of a type IPublishedContent, but of type HomePage and you can use rootnode.TopNotifications
(Use the type of your root node),Or if you do not use ModelsBuilder you could use the method like this:
For reference, check out this: https://our.umbraco.com/Documentation/Fundamentals/Backoffice/Property-Editors/Built-in-Property-Editors/Block-List-Editor/index-v8 It's mostly explained here how to render it.
Edit: Now that I read it again, you most like need use the
@Html.GetBlockListHtml(Model, "TopNotifications")
. I've added some explanation as to why the error says what it says.Hope this helps!
is working on a reply...