html.renderPartial ... from IPublishedElement to IPublishedContent
I am using the new BlockList to add layout elements to a node. (Inside each layout is another Blocklist which allows users to add blocks of content to the layout area.)
I call the layouts thusly:
var varBlocks = Model.WContent12;
foreach (var varBlock in varBlocks)
{
var varBlockContent = varBlock.Content;
var varBlockSettings = varBlock.Settings;
string strPartial = "features/" + varBlockContent.ContentType.Alias;
@Html.Partial(strPartial, varBlockContent);
}
So far, so good.
However, in one particular layout, I wish to add a left navigation automatically. I have done this in other websites and intend to reuse the code. I would normally just use @Html.renderPartial("leftnav") and all would be good.
Except that at this point I am calling the partial from inside the BlockList element. That means I am trying to call IPublishedContent from IPublishedElement.
If I just use the straight renderPartial I get a Cannot bind source type Umbraco.Core.Models.etc... error
I therefore need a method for referring back to the model that called the element, and passing that through in the partial call. Something like: @Html.renderPartial("leftnav", doctypeThatCalledThisElement)
I remember something along these lines using nested content, but it is buried in the codes of time. Any ideas?
In case anyone else is in this pickle the way out is: Umbraco.AssignedContentItem - this will give you the model of the node that is calling the blocklist element.
html.renderPartial ... from IPublishedElement to IPublishedContent
I am using the new BlockList to add layout elements to a node. (Inside each layout is another Blocklist which allows users to add blocks of content to the layout area.)
I call the layouts thusly:
So far, so good.
However, in one particular layout, I wish to add a left navigation automatically. I have done this in other websites and intend to reuse the code. I would normally just use
@Html.renderPartial("leftnav")
and all would be good.Except that at this point I am calling the partial from inside the BlockList element. That means I am trying to call IPublishedContent from IPublishedElement.
If I just use the straight renderPartial I get a
Cannot bind source type Umbraco.Core.Models.etc...
errorI therefore need a method for referring back to the model that called the element, and passing that through in the partial call. Something like:
@Html.renderPartial("leftnav", doctypeThatCalledThisElement)
I remember something along these lines using nested content, but it is buried in the codes of time. Any ideas?
In case anyone else is in this pickle the way out is:
Umbraco.AssignedContentItem
- this will give you the model of the node that is calling the blocklist element.as in:
Html.RenderPartial("leftnav", Umbraco.AssignedContentItem)
is working on a reply...