Hi all, I have a weird rendering problem with Razor script files. Effectively, it doesn't execute anything inside of he helper methds. I even tried putting a int x=0;int y=0;int z=x/y; to get an exception, and it wasn't thrown.
Another thing I have that does not work is @Html.Raw("") will not write anything out. What I have seen does work, is when you put a <ul></ul> in the body of script (not in the helpers) it would get written out. During a debugging step through of the code, it says it hits the helper, but never does anything in it, just jumps right back out, never goes through any of the lines in it.
Am I doing this in the wrong spot in Umbraco?
My script/macro:
@inherits umbraco.MacroEngines.DynamicNodeContext
@using umbraco.MacroEngines;
@helper LI(DynamicNode item){
<li>
<a href="@(item.Url)">@(item.Name)</a>
@{
IEnumerable<DynamicNode> children = item.Children.Where(p => p.Visible);
UL(children);
}
</li>
}
@helper UL(IEnumerable<DynamicNode> items){
<ul>
@{
//divide by zero exception stuff was here
foreach (DynamicNode item in items)
{
LI(item);
}
}
</ul>
}
@{
DynamicNode root = Model as DynamicNode;
DynamicNode model = root;
root = root.AncestorOrSelf(1);
while (root.Parent != null)
{
root = root.Parent;
}
IEnumerable<DynamicNode> rootMenu = root.Children.Where(p => p.Visible);
UL(rootMenu);
@helper UL(IEnumerable<DynamicNode> items){ <ul> @{ //divide by zero exception stuff was here foreach (DynamicNode item in items) { @LI(item); } } </ul> } @{ DynamicNode root = Model as DynamicNode; DynamicNode model = root; root = root.AncestorOrSelf(1);
while (root.Parent != null) { root = root.Parent; }
Thanks for the tip, it worked great. I've used razor in other MVC apps for the past year, but I've never used helper methods (didn't know they even existed), they are pretty neat. Its amazing how much you learn every day.
@helper methods not executing in 6.0.6
Hi all, I have a weird rendering problem with Razor script files. Effectively, it doesn't execute anything inside of he helper methds. I even tried putting a int x=0;int y=0;int z=x/y; to get an exception, and it wasn't thrown.
Another thing I have that does not work is @Html.Raw("") will not write anything out. What I have seen does work, is when you put a <ul></ul> in the body of script (not in the helpers) it would get written out. During a debugging step through of the code, it says it hits the helper, but never does anything in it, just jumps right back out, never goes through any of the lines in it.
Am I doing this in the wrong spot in Umbraco?
My script/macro:
Hello Edward,
you should call your helpers with @helpername. I tried your code this way and it was working.
Hope it's working for you as well.
Greets,
Theresa
Thanks for the tip, it worked great. I've used razor in other MVC apps for the past year, but I've never used helper methods (didn't know they even existed), they are pretty neat. Its amazing how much you learn every day.
is working on a reply...