Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
From a Razor newbie... Why does this function call work:
@RenderChildren(node.Children.Where("NodeTypeAlias == @0 or NodeTypeAlias == @1 and Visible", "FP_Page", "FP_Home"));
whereas this does not:
dynamic children = node.Children.Where("NodeTypeAlias == @0 or NodeTypeAlias == @1 and Visible", "FP_Page", "FP_Home");
RenderChildren(children);
Am i doing something wrong? Declaring the variables wrong perhaps?
I dont get an error or anything, it just doesnt call the function in the second case... the entire code block & helper function looks like this:
@helper RenderNodes(dynamic nodes) { foreach (var node in nodes) { var selected = Array.IndexOf(Model.Path.Split(','), node.Id.ToString()) >= 0 ? " class=\"current\"" : ""; <li> <a @Html.Raw(selected) href="@node.Url" title="@node.Name" >@node.Name</a> @RenderChildren(node.Children.Where("NodeTypeAlias == @0 or NodeTypeAlias == @1 and Visible", "FP_Page", "FP_Home")); @* @{ dynamic children = node.Children.Where("NodeTypeAlias == @0 or NodeTypeAlias == @1 and Visible", "FP_Page", "FP_Home"); RenderChildren(children); } *@ </li> } } @helper RenderChildren(dynamic childNodes) { <p>children: @childNodes.Items.Count</p> <ul> @foreach (dynamic node in childNodes) { var selected = Array.IndexOf(Model.Path.Split(','), node.Id.ToString()) >= 0 ? " class=\"current\"" : ""; <li><a @Html.Raw(selected) href="@node.Url" title="@node.Name" >@node.Name</a></li> } </ul> }
I've worked around the above issue by putting a condition around the code block in the RenderChildren helper.. but I'd still love to know why i can't get that other call to work...
@helper RenderNodes(dynamic nodes) { foreach (var node in nodes) { var selected = Array.IndexOf(Model.Path.Split(','), node.Id.ToString()) >= 0 ? " class=\"current\"" : ""; <li> <a @Html.Raw(selected) href="@node.Url" title="@node.Name" >@node.Name</a> @RenderChildren(node.Children.Where("NodeTypeAlias == @0 or NodeTypeAlias == @1 and Visible", "FP_Page", "FP_Home")) </li> } } @helper RenderChildren(dynamic childNodes) { if (@childNodes.Items.Count > 0) { <ul> @foreach (dynamic node in childNodes) { var selected = Array.IndexOf(Model.Path.Split(','), node.Id.ToString()) >= 0 ? " class=\"current\"" : ""; <li><a @Html.Raw(selected) href="@node.Url" title="@node.Name" >@node.Name</a></li> } </ul> } }
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Simple Razor Question
From a Razor newbie... Why does this function call work:
whereas this does not:
Am i doing something wrong? Declaring the variables wrong perhaps?
I dont get an error or anything, it just doesnt call the function in the second case... the entire code block & helper function looks like this:
I've worked around the above issue by putting a condition around the code block in the RenderChildren helper.. but I'd still love to know why i can't get that other call to work...
is working on a reply...