Copied to clipboard

Flag this post as spam?

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


  • Matt 353 posts 825 karma points
    Dec 17, 2018 @ 14:26
    Matt
    0

    Something wrong with my code?

    Hello all,

    Hope you had a good weekend.

    I'm having issues with a code I'm trying to use;

                  <div>@Model.Content.Name</div>
        <div class="product-column w-row">
        @foreach(var product in Model.Content.Children())
          {
          <div class="product-col w-col w-col-4">
              <div class="product-div" data-ix="show-thumnail-block">
                <div class="product-image">
     var productImage = product.GetPropertyValue<IPublishedContent>("productImage");
    
        @if (productImage != null)
        {
            <div class="thumbnail-block" data-ix="hide-thumbnail"><a href="@productImage.Url" class="product-button w-button">View Item</a></div>
        }        
                        <h1 class="product-item-title">@product.Name</h1>
    
              </div>
            </div>
          } 
    
     </div>
    

    I keep getting the following error;

    "Parser Error Message: The foreach block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup."

    But I cannot work out whats causing this? I'm sure its something simple I'm missing!

    Thanks in advance,

    Matt

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Dec 17, 2018 @ 14:32
    Nik
    0

    Hi Matt,

    I think you are missing a </div> before your } for the for each loop. You currently have 2, but I think you need 3.

    Thanks

    Nik

  • Matt 353 posts 825 karma points
    Dec 17, 2018 @ 14:34
    Matt
    0

    Hello Nik,

    Thanks for quick reply, Thought there was something!

    Although Its now changed to the following;

    Compiler Error Message: CS0103: The name 'productImage' does not exist in the current context
    

    Thanks

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Dec 17, 2018 @ 14:40
    Nik
    0

    Hi Matt,

    Okay replace your code with this... The reason is Razor formatting and behaviour so it's easier to give you code you can then compare against what you currently have to see the differences. You are basically there though.

    <div>@Model.Content.Name</div>
        <div class="product-column w-row">
            @foreach(var product in Model.Content.Children())
            {
                <div class="product-col w-col w-col-4">
                    <div class="product-div" data-ix="show-thumnail-block">
                        <div class="product-image">
                            @{ 
                                var productImage = product.GetPropertyValue<IPublishedContent>("productImage");
                                if (productImage != null)
                                {
                                    <div class="thumbnail-block" data-ix="hide-thumbnail"><a href="@productImage.Url" class="product-button w-button">View Item</a></div>
                                }        
                            }
                            <h1 class="product-item-title">@product.Name</h1>
                        </div>
                    </div>
                </div>
            } 
        </div>
    
  • Matt 353 posts 825 karma points
    Dec 18, 2018 @ 13:20
    Matt
    0

    Ahh so close! :(

    Thanks Nik that sort it.

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Dec 18, 2018 @ 13:37
    Nik
    0

    No worries Matt. It's one of those things that can be hard to spot when you get an error message that isn't really telling you the actual issue :-)

Please Sign in or register to post replies

Write your reply to:

Draft