Copied to clipboard

Flag this post as spam?

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


  • Michael Beever 74 posts 155 karma points
    Aug 11, 2020 @ 14:04
    Michael Beever
    0

    Hello

    I am writing a piece of code that pulls content from another page.

    The page should only display the associated content of that page and therefore need a ForEach and If statement.

    This is what I have so far.

     @{
    
                        var DocContentPage = DocPage.docNested;
                        foreach (var item in DocContentPage)
                        {
    
                        var SelectionId = @item.DocumentFilter;
    
                        string RadioTextValue = umbraco.library.GetPreValueAsString(SelectionId);
    
                            if(@RadioTextValue == "Trust Documents")
                            {   
                                <div class="col-md-6">
    
                                    <h3>@item.DocumentTitle</h3>
                                    <p>@item.DocumentDescription</p>
                                    <p><a class="btn btn-secondary" href="@item.FileUpload.Url" target="_blank" role="button"><i class="fas fa-file-pdf"></i> View here</a></p>
    
                                </div>
                            }
    
                        }
    
                    } 
    

    The error I get is:

    Compiler Error Message: CS1513: } expected

    Source Error:

    Line 293: } Line 294: } Line 295:}

    Source File: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\f96f3538\6042b992\AppWebdocumentdisplaycontent.cshtml.65a2d1ee.dyfupqad.0.cs Line: 295

    I cannot understand why this is happening, I believe it has something to do with the if statement but not sure what.

    Thanks

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Aug 11, 2020 @ 14:08
    Steve Morgan
    0

    Hi,

    It's important to understand in Razor when you need a @ and when you don't.

    Imagine it as a switch - you only need it to switch from "html mode" to "code mode".

    If you're already in "code mode" then don't use @ s!

    Steve

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Aug 11, 2020 @ 14:09
    Steve Morgan
    100
        @{    // you have entered "code mode" here - unless you open an html tag it will stay in "code mode"
    
        var DocContentPage = DocPage.docNested;
        foreach (var item in DocContentPage)
        {
    
            var SelectionId = item.DocumentFilter;
    
            string RadioTextValue = umbraco.library.GetPreValueAsString(SelectionId);
    
            if (RadioTextValue == "Trust Documents")
            {
                <div class="col-md-6">
    @* you have entered into html mode ! *@ 
                    <h3>@item.DocumentTitle</h3>
                    <p>@item.DocumentDescription</p>
                    <p><a class="btn btn-secondary" href="@item.FileUpload.Url" target="_blank" role="button"><i class="fas fa-file-pdf"></i> View here</a></p>
    
                </div>
            }
        }
    }
    
  • Michael Beever 74 posts 155 karma points
    Aug 11, 2020 @ 14:12
    Michael Beever
    0

    Steve thank you very much sorted.

    Never come across that before.

Please Sign in or register to post replies

Write your reply to:

Draft