Copied to clipboard

Flag this post as spam?

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


  • Robert J. Bullock 386 posts 405 karma points
    Jun 02, 2011 @ 22:44
    Robert J. Bullock
    0

    Return to Bracket Hell

    No matter what I do, I get an error telling me some ending bracket is missing in my Razor macro. Driving me nuts. Has anyone else run into this problem?

  • Robert J. Bullock 386 posts 405 karma points
    Jun 02, 2011 @ 23:11
    Robert J. Bullock
    0

    For example, what's wrong with this code? The brackets are totally balanced as far as a I can see:

    <div class="tabs-container">

    @foreach (var day in @Model.scheduleDay.Where("Visible"))

    {

      <div id="@day.Id" class="tab-content">

      @if(day.Children.Count() != 0){

      foreach(var time in @day.Children){

      <h3>@time.Name</h3>

        if(time.Children.Count()>0){

              foreach(var event in time.Children){

              var photo = @event.image;

              <h2>@event.title</h2>

              if(!String.IsNullOrEmpty(photo)){<img src="/ImageGen.ashx?image=@event.image&width=150" alt="@event.title" class="photo" />}

              <p>@event.description</p>

              }

        }

       }

      }

      </div>

     }

    </div>

  • James Patterson 53 posts 192 karma points
    Jun 03, 2011 @ 00:39
    James Patterson
    1

    Spotted it. You're using 'event' as your variable name in the last foreach. I bet it's throwing a fit because it's a C# keyword. Change it (and the uses of it) to something like 'child' and it works.

    <div class="tabs-container">
        @foreach (var day in @Model.scheduleDay.Where("Visible"))
        {
            <div id="@day.Id" class="tab-content">
            @if(day.Children.Count(!= 0)
            {
                foreach(var time in @day.Children)
                {
                    <h3>@time.Name</h3>
                    if(time.Children.Count()>0)
                    {
                        foreach(var child in time.Children)
                        {
                            var photo @child.image;
                            <h2>@child.title</h2>

                            if (!String.IsNullOrEmpty(photo))
                            {
                                <img src="/ImageGen.ashx?image=@child.image&width=150" alt="@child.title" class="photo" />
                            }

                            <p>@child.description</p>
                        }
                    }
                }
            }
            </div>
        }
    </div>
  • Robert J. Bullock 386 posts 405 karma points
    Jun 03, 2011 @ 02:49
    Robert J. Bullock
    0

    DOH!!! You're right! Oh man, I'm a moron!

    Can I buy you a beer? ;-)

  • James Patterson 53 posts 192 karma points
    Jun 03, 2011 @ 09:01
    James Patterson
    0

    Don't be so hard on yourself, easy mistake to make! I'd have done the same thing no doubt.

    High five/mark the answer and we're even :-)

  • 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