Not able to get value of NodeByID in loop or after passing to @RenderPage("",NodeID);
As Following is my Scripting File Code
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var MenuNode = Library.NodeById(2001);
@foreach (var SubItem in MenuNode.Children)
{
var SubNode Library.NodeById(SubItem.SelectedNode) // << Not able to fetch node
var SubNode Library.NodeById(3031) // << I have also tried with static Node Id , But was not able to get node value
<h2> @SubNode.Name </h2>
}
}
I am not able to fetch the value of node in site foreach.
As I have try with
var SubNode Library.NodeById(3031)
var SubNode @Model.NodeById(3031)
dynamic SubNode = new umbraco.MacroEngines.DynamicNode(3130);
etc.
but I am not able to get the value of Node. by ID in foreach loop.
I have tried with UmbracoHelper , it's working when I give static value .. :)
@foreach (var SubItem in MenuNode.Children)
{
var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current)
var nodeContent = umbracoHelper.Content(2001); < Passing static value it is working.
<h2> @SubNode.Name </h2>
}
But when I pass content picker value (SubItem.SelectedNode) , do not work :(
@foreach (var SubItem in MenuNode.Children)
{
var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current)
var nodeContent = umbracoHelper.Content(SubItem.SelectedNode); < have also try with converting to int.
<h2> @SubNode.Name </h2>
}
Then you should be able to do something like this,
<ul>
@foreach(var subItem in MenuNode.Children){
@*For each link, get the node, and display its name and url*@
var node = Library.NodeById(subItem.selectedNode);
<li><a href="@node.Url">@node.Name</a></li>
}
</ul>
Make sure that the alias of your content picker is correct, if you don´t change it then it will take the name of your property, starting with lowercase.
Not able to get Node by ID in foreach
Not able to get value of NodeByID in loop or after passing to @RenderPage("",NodeID);
As Following is my Scripting File Code
I am not able to fetch the value of node in site foreach.
As I have try with
etc.
but I am not able to get the value of Node. by ID in foreach loop.
so how can I access it ?
Thanks , BJ
Hi,
I would recommend using Umbraco Helper methods instead.
https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/70701-whats-the-difference-between-using-librarynodebyid-1052-and-umbracocontent-id
Hi Martin,
Thanks for your reply,
I have tried with UmbracoHelper , it's working when I give static value .. :)
But when I pass content picker value (SubItem.SelectedNode) , do not work :(
Hi BJ
You should be able to do something like this to get it it to work.
You can find all the built in property documentation here. https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/ including the content picker
Hope this helps,
/Dennis
Thanks Dennins,
But When I inject following code
I am getting following error. Msg.
FYI : I am using umbraco 6
Hi BJ,
What is the first line of your Razor file, something like this.
When we know this it´s much easier to help you in the right directions.
/Dennis
Hi Dennis,
it's
@inherits umbraco.MacroEngines.DynamicNodeContext
Hi BJ
Then you should be able to do something like this,
Make sure that the alias of your content picker is correct, if you don´t change it then it will take the name of your property, starting with lowercase.
Hope this helps you in the right direction,
/Dennis
Hi Dennis,
No it's not working for me :(
As per my first post I am able to get node using
But outside the scope of foreach...!
Hey BJ!
I just stumbled onto this thread while trying to solve a similar (exact) problem. I came across a few things:
Library.NodeById
is deprecated. Reference.Umbraco.Content()
to retrieve the node in question.int
in order forUmbraco.Content
to function correctly.Here's an abbreviated application of this:
Hopefully this helps you as it has me. I was stumped on this issue for a bit.
Good luck!
UPDATE:
This works a little unusual as this cast actually causes the partial to fail when rendering if it's applied outside of the
foreach
loop.is working on a reply...