Copied to clipboard

Flag this post as spam?

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


  • Drew DeVault 22 posts 43 karma points
    Oct 13, 2011 @ 20:16
    Drew DeVault
    0

    Error CS0103 in Razor Script

    I'm working on a macro in razor and keep running into a strange issue:

    @{
    var startNode = @Model.AncestorOrSelf().Regions.First();
    }

    <ul>
        <li>
            <a href="@startNode.Url">Home</a>
        </li>
        @{ int index = 0; }
        foreach (var contentItem in @startNode.ContentPages)
        {
        <li @(startNode.ContentPages.Count() - 1 == index ? "style=border-right:none;":null)>
            <a href="@contentItem.Url">@contentItem.Name</a>
        </li>
        index++;
      }
    </ul>

    This code returns this error:

    Navigation.cshtml(13): error CS0103: The name 'contentItem' does not exist in the current context

     

    Any ideas?

  • Rodion Novoselov 694 posts 859 karma points
    Oct 13, 2011 @ 20:23
    Rodion Novoselov
    0

    Hi. Try to add a '@' sign right before 'foreach'.

  • Drew DeVault 22 posts 43 karma points
    Oct 13, 2011 @ 20:25
    Drew DeVault
    0

    Works great, thanks!  I can't believe I didn't see that.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies