When you are inside a code region you should not use @, for instance @Parameter should just be Parameter. I also noticed that you have put a Take(1) in the last foreach, this will only give you one item. Is that the intention? I have changed your code a bit to fix the obvious errors:
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var idelem = Parameter.idelem;
var num = Parameter.num;
var countNodes = Model.NodeById(idelem).Children.Count();
Did you try debugging by changing the url in the browser by appending ?umbDebugShowTrace=true
That should give you a better error message pinpointing the offending code line. If you could copy the error message in here I am sure we can find the error.
Rebuild your razor code step by step to identify the part where the error occurs and make use of the debugging possibilities. It is hard to identify a problem just by reading your code.
I could identify the error, was that he was checking a string to an integer and so gave the error. I've solved the problem thank you very much to both.
Why it fails?
Hello friends!. I do not know what the hell, I'm doing this code, it is giving me error. I'm using version
Umbraco 4.11.5
Error loading MacroEngine script (file: TemasGen.cshtml)
This is the code:
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var idelem = @Parameter.idelem;
var num = @Parameter.num;
var countNodes = @Model.NodeById(idelem).Children.Count();
}
@if(num < countNodes){
num = countNodes;
}
@if(countNodes > 0){
<article>
<h2><a href="#" class="transition-dot3">InformaciĆ³n General</a></h2>
<ul>
@foreach (var item in @Model.NodeById(idelem).Children.Take(1))
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
</article>
}
Hi,
When you are inside a code region you should not use @, for instance @Parameter should just be Parameter. I also noticed that you have put a Take(1) in the last foreach, this will only give you one item. Is that the intention? I have changed your code a bit to fix the obvious errors:
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var idelem = Parameter.idelem;
var num = Parameter.num;
var countNodes = Model.NodeById(idelem).Children.Count();
}
@if(num < countNodes){
num = countNodes;
}
@if(countNodes > 0){
<article>
<h2><a href="#" class="transition-dot3">InformaciĆ³n General</a></h2>
<ul>
@foreach (var item in Model.NodeById(idelem).Children))
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
</article>
}
If you still have errors try to enable the debugging by adding ?umbDebugShowTrace=true to your url. That will give you more detail on the error.
/Carsten
Thank you friend!
I tried without the "@", but still gives the same error.
I want to use "Take ()" to limit the results, as chosen in the macro.
<umbraco:Macro idelem="1073" num="7" Alias="TemasGen" runat="server"></umbraco:Macro>
Any other solution. Greetings!
Did you try debugging by changing the url in the browser by appending ?umbDebugShowTrace=true
That should give you a better error message pinpointing the offending code line. If you could copy the error message in here I am sure we can find the error.
Rebuild your razor code step by step to identify the part where the error occurs and make use of the debugging possibilities. It is hard to identify a problem just by reading your code.
I could identify the error, was that he was checking a string to an integer and so gave the error. I've solved the problem thank you very much to both.
Using this, I realized the problem.
@num.GetType ();
@countNodes.GetType ();
BTW. How do I use "?UmbDebugShowTrace=true"?
Thus for example be used:
http://mysite.com?umbDebugShowTrace=true
http://mysite.com/home.aspx?umbDebugShowTrace=true
Greetings!
is working on a reply...