Copied to clipboard

Flag this post as spam?

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


  • J 445 posts 862 karma points
    Mar 18, 2016 @ 09:31
    J
    0

    Why doesnt this code print "NewString" value? It prints the text only (as in the code itself) but not the value (in this case the destination once the , is stripped off)?

      @foreach (var childPage in Model.Children.Where("Visible"))
        {
            <li>
    
                <a href="@childPage.Url">@childPage.Name</a>
    
                 var myString = @childPage.Destination.ToString();
                 var NewString = myString.Split(',').Last();
    
    
                  New string is <span>NewString</span>
    
                @* if the current page has any children, where the property umbracoNaviHide is not True *@
                @if (childPage.Children.Where("Visible").Any())
                {
                    @* Call our helper to display the children *@
                    @childPages(childPage.Children )
                }
            </li>
        }
    
  • Aristotelis Pitaridis 84 posts 402 karma points
    Mar 18, 2016 @ 09:57
    Aristotelis Pitaridis
    0

    Change this line of code with the of following:

    New string is <span>@NewString</span>
    
  • J 445 posts 862 karma points
    Mar 18, 2016 @ 10:14
    J
    0

    I tried that and get the error

    The name 'NewString' does not exist in the current context

  • Aristotelis Pitaridis 84 posts 402 karma points
    Mar 18, 2016 @ 10:40
    Aristotelis Pitaridis
    0

    Try to move your variables before the li tag. I have not tested it but this is what I would type:

    @foreach (var childPage in Model.Children.Where("Visible"))
    {
        var myString = @childPage.Destination.ToString();
        var NewString = myString.Split(',').Last();
        <li>
            <a href="@childPage.Url">@childPage.Name</a>
    
            New string is <span>@NewString</span>
    
            @* if the current page has any children, where the property umbracoNaviHide is not True *@
            @if (childPage.Children.Where("Visible").Any())
            {
                @* Call our helper to display the children *@
                @childPages(childPage.Children)
            }
        </li>
    }
    
  • Rhys Hamilton 20 posts 89 karma points
    Mar 18, 2016 @ 11:16
    Rhys Hamilton
    0

    Perhaps you answered your own question.

    The code @childPage.Destination.ToString() may instead be @childPage.Destination.Value.ToString()

    Or something along those lines.

Please Sign in or register to post replies

Write your reply to:

Draft