I am trying to get node by hard coded id and then its children.
I tried the following code,
dynamic node = new DynamicNode(1052);
<p>@node.Id</p> // output is 1052
<p>@node</p>
foreach(var item in @node.Children().Where("Visible"))
{
<p>@item.movingClean</p> // output of this line is "System.Collections.Generic.List`1[System.String[]]"
//expected output is the values from each children corresponding to the alias "movingClean"
//"movingclean" is alias of textstring array
}
Working code without using dynamic node is as follows:
foreach (var item in CurrentPage.Children().Where("Visible"))
{
var count = 0;
foreach (var counter in item.movingclean)
{
count = count + 1;
}
for (int i = 0; i < count; i++){
foreach (var qLoop in item.movingclean[i]){
<p>@qLoop.InnerText</p>
}
}
}
@{
var node = Library.NodeById(1052);
<p>@node.Id</p> // output is 1052
<p>@node</p>
foreach (var item in node.Children.Where("Visible"))
{
<p>@item.movingClean</p> // output of this line is "System.Collections.Generic.List`1[System.String[]]"
//expected output is the values from each children corresponding to the alias "movingClean"
}
}
Do i need to add any assembly reference for Library?
@Dennis
Following error occurred when i tried the code,
CS1061: 'Umbraco.Web.Models.RenderModel' does not contain a definition for 'NodeById' and no extension method 'NodeById' accepting a first argument of type 'Umbraco.Web.Models.RenderModel' could be found (are you missing a using directive or an assembly reference?)
@fiji
Error occurs :-(
CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
Actually your error message indicates you are using Mvc, however your code samples are for non Mvc Razor Macros, try this instead:
@{
var node = Umbraco.Content(1052);
<p>@node.Id</p> // output is 1052
foreach (var item in node.Children.Where("Visible"))
{
<p>@item.movingClean</p> // output of this line is "System.Collections.Generic.List`1[System.String[]]"
//expected output is the values from each children corresponding to the alias "movingClean"
}
}
You're welcome! It's a bit confusing with MVC & non MVC Razor support in Umbraco, when posting a topic here it's worth saying you are using MVC (or not) as it will help get you to the answer :-)
If you're using MVC in version 6, I question whether you need the umbraco.MacroEngines and umbraco.NodeFactory namespaces at all?
But to answer your question, it seems you want to use a custom model in your partial view, but still have access to the umbraco helpers and nodes, etc.
Try @inherits Umbraco.Web.Mvc.UmbracoViewPage<YourCustomModel> and you should still be able to call upon Umbraco helper. Hopefully I did not misunderstand what you are trying to do... If so could you post how you are trying to include your partial?
Yes, the answer is exactly as Funka has suggested and also he is right to say you shouldn't be referencing those namespaces either, they are not needed and would potentially cause you issues.
Get node by id and chidren
Hi all,
I am trying to get node by hard coded id and then its children.
I tried the following code,
Working code without using dynamic node is as follows:
umbraco 6.1.6
How can i get the items in children?
Please help,
Thanks
Hi Erma,
Try this one instead:
Hope this helps
/Dennis
Hi Erma,
Try this:
Jeavon
Try something like
@Jeavon
Do i need to add any assembly reference for Library?
@Dennis
Following error occurred when i tried the code,
@fiji
Error occurs :-(
CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
Hi Erma,
Actually your error message indicates you are using Mvc, however your code samples are for non Mvc Razor Macros, try this instead:
Jeavon
@Jeavon
Thank you thank you thank you
It worked :-)
You're welcome! It's a bit confusing with MVC & non MVC Razor support in Umbraco, when posting a topic here it's worth saying you are using MVC (or not) as it will help get you to the answer :-)
@Jeavon
One more doubt.
What need to be changed to make the above code work in a partial view?
Let me clarify my question,
My partial contains following model and assemblies,
Since i am using model, i couldn't be able to inherit
How can i make above code work here?
Please help,
If you're using MVC in version 6, I question whether you need the umbraco.MacroEngines and umbraco.NodeFactory namespaces at all?
But to answer your question, it seems you want to use a custom model in your partial view, but still have access to the umbraco helpers and nodes, etc.
Try
@inherits Umbraco.Web.Mvc.UmbracoViewPage<YourCustomModel>
and you should still be able to call uponUmbraco
helper. Hopefully I did not misunderstand what you are trying to do... If so could you post how you are trying to include your partial?Yes, the answer is exactly as Funka has suggested and also he is right to say you shouldn't be referencing those namespaces either, they are not needed and would potentially cause you issues.
Jeavon...that's twice so far this month your Umbraco mastery has helped me out...THANK YOU
Hi Brian,
Brilliant, even better when the answer already exists!
Jeavon
This is working with umbraco 6 and version 7 + as well , let me know if it works for you.
Arjun, this is a very old thread you comment on, however you shouldn't ever be using DynamicNode in Umbraco v7
is working on a reply...