Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Greg 9 posts 29 karma points
    Mar 04, 2013 @ 17:48
    Greg
    0

    Macro - Use of unassigned local variable

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        IPublishedContent practiceAreas;
        foreach (IPublishedContent page in Model.CurrentPage.Children)
        {
            if (page.Name == "Practice Areas")
            {
                practiceAreas = page;
                break;
            }
        }
    }
    <ul class="homePraticeAreasNav">
        @foreach (var item in practiceAreas.Children)
        { 
            <li><a class="navigation" href="@item.Url()">@item.Name</a></li>
        }
    </ul>

    I'm getting a "Use of unassigned local variable" on 'practiceAreas' on the foreach loop. Anyone know why?

  • Greg 9 posts 29 karma points
    Mar 04, 2013 @ 19:04
    Greg
    0

    Scratch my question... looks like this is what I needed:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        var node = Model.CurrentPage.Descendants().Where(x => x.Name == "Practice Areas").FirstOrDefault();
    }
    <ul class="homePraticeAreasNav">
        @foreach (var item in node.Children() )
        { 
            <li><a class="navigation" href="@item.Url()">@item.Name</a></li>
        }
    </ul>
Please Sign in or register to post replies

Write your reply to:

Draft