Nested Content Items are 'detached' content items which means they have no relationship back to their parent or other bits of content. So the answer is you can't the ID of the page the nested content is on directly from the nested Content Item : (
you can get the current page from the UmbracoContext.
@UmbracoContext.Current.PageId
but it is probably best practice to pass the page id (or the things you need) to any partial that handles the nested content
@Html.Partial("nestedPartial", nestedItem, new ViewDataDictionary {
{ "CurrentPageId", Model.Id }
})
you can then get this in the parial . with ViewData["CurrentPageId"]
if you need to access the current page model - then it's probibly better to actually pass that to the partial and get the NestedContent Items within the partial ? - or at least pass the model as well as the nested content - that way you won't have to do re-lookup the page model in your code.
I solved the problem with this workaroud.
I create in app_code a my class:
u
sing System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web;
using Umbraco.ModelsBuilder;
using Umbraco.ModelsBuilder.Umbraco;
namespace RedConsulting
{
public class RedPoint
{
public IPublishedContent point{get; set;}
public int nodeID {get; set;}
}
}
Then into the page:
List<RedPoint> elenco = new List<RedPoint>();
var selectionPercorsi = Model.Content.Site().FirstChild("products").Children("product")
.Where(x => x.IsVisible());
foreach(var item in selectionPercorsi){
var points = item.GetPropertyValue<IEnumerable<IPublishedContent>>("points");
int nodeid = item.Id;
foreach(IPublishedContent itemp in points)
{
RedPoint rp = new RedPoint();
rp.point = itemp;
rp.nodeID= nodeid;
elenco.Add(rp);
}
}
The rp.nodeID contain the ID of "parent" and then you can access data with
var nodeParentContent = Umbraco.Content(itemrp.nodeID);
Solved - How to get the page id of the current nested content?
How to get the page id of the current nested content?
Hi
Nested Content Items are 'detached' content items which means they have no relationship back to their parent or other bits of content. So the answer is you can't the ID of the page the nested content is on directly from the nested Content Item : (
you can get the current page from the UmbracoContext.
but it is probably best practice to pass the page id (or the things you need) to any partial that handles the nested content
you can then get this in the parial . with
ViewData["CurrentPageId"]
if you need to access the current page model - then it's probibly better to actually pass that to the partial and get the NestedContent Items within the partial ? - or at least pass the model as well as the nested content - that way you won't have to do re-lookup the page model in your code.
I solved the problem with this workaroud. I create in app_code a my class:
u
Then into the page:
The rp.nodeID contain the ID of "parent" and then you can access data with
var nodeParentContent = Umbraco.Content(itemrp.nodeID);
is working on a reply...