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
Hi,
I am new to Razor and I am having some trouble.
I have the following code inline:
<umbraco:Macro Language="cshtml" runat="server" recursive="true"> @foreach (var page in Model.AncestorOrSelf(1).Children.Where("Visible")) { <li><a class="menu-1" href="@page.Url">@page.Name</a> @if (page.Children.Where("Visible").Count() > 0) { <li><a class="sub1" href="@page.Url">@page.Name</a> <ul> @foreach (var subpage in page.Children.Where("Visible")) { <li><a href="@subpage.Url">@subpage.Name</a></li> } </ul> </li> } else { <li><a class="menu-1" href="@page.Url">@page.Name</a></li> } } </umbraco:Macro>
This gives me: Error loading MacroEngine script (file: )
I can't figure out what the issue is.
Thank you!
I can't seem to edit the post, so I can't delete the first <li> after the @foreach.
It is a copying error. Sorry.
This seems to work:
@{ <ul> @foreach (var page in Model.AncestorOrSelf(1).Children.Where("Visible")) { if (page.Children.Where("Visible").Count() > 0) { <li><a class="sub1" href="@page.Url">@page.Name</a> <ul> @foreach (var subpage in page.Children.Where("Visible")) { <li><a href="@subpage.Url">@subpage.Name</a></li> } </ul> </li> } else { <li><a class="menu-1" href="@page.Url">@page.Name</a></li> } } </ul>}
You had an extra @ sign in front of your first if statement.
Yep. That was it. Silly me :) I'm so new to Razor I'm not even 100% on the syntax. I should get a book or something.
Yeah, and then Umbraco 4's razor has some things only specific to it as well.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Multi-level menu not working
Hi,
I am new to Razor and I am having some trouble.
I have the following code inline:
This gives me: Error loading MacroEngine script (file: )
I can't figure out what the issue is.
Thank you!
I can't seem to edit the post, so I can't delete the first <li> after the @foreach.
It is a copying error. Sorry.
This seems to work:
You had an extra @ sign in front of your first if statement.
Yep. That was it. Silly me :) I'm so new to Razor I'm not even 100% on the syntax. I should get a book or something.
Thank you!
Yeah, and then Umbraco 4's razor has some things only specific to it as well.
is working on a reply...