I’m trying to create a top navigation in Umbraco 4.10.1 that is based upon the children of my home page.
Initially I had tried the following, but kept getting “Error loading Razor Script” in place of my navigation:
<umbraco:Macro runat="server" language="cshtml">
@inherits umbraco.MacroEngines.DynamicNodeContext
<ul>
@foreach (var item in Model.AncestorOrSelf(1048).Children.Where("Visible"))
{
<li><a href="@item.Url">@item.Name</a></li>
}
</ul>
</umbraco:Macro>
When I run in Debug Mode through VS 2012, it breaks on the @foreach line. When I inspect Model, it does not include AncestorOrSelf. Am I missing a using?
Once I couldn’t get that working, I included the pre-written Navigation macro, but it also shows the “Error loading Razor Script”.
The problem seemed to stem from upgrading Razor to V2. With a clean install and the original version of Razor that is included in the NuGet package, the navigation code posted above works just fine.