Copied to clipboard

Flag this post as spam?

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


  • Mike Poole 53 posts 165 karma points
    Sep 07, 2018 @ 10:20
    Mike Poole
    0

    SurfaceController not able to access CurrentPage

    I have a SurfaceController that performs a Get method. When I attempt to access the current page using this.CurrentPage, I get the following error

    Cannot find the Umbraco route definition in the route values, the request must be made in the context of an Umbraco request

    Why is my controller not able to see the current page?

    { using System; using System.Threading.Tasks; using System.Web.Mvc; ... using Umbraco.Web.Mvc;

    public class BenefitStatementPdfSurfaceController : SurfaceController
    {
        private readonly SelfServiceApiHttpClient _apiClient;
    
        public MySurfaceController(SelfServiceApiHttpClient apiClient)
        {
            _apiClient = apiClient;
        }
    
        [ActionName("MemberPdf")]
        [HttpGet]
        [Authorize]
        public async Task<ActionResult> MemberPdfAsync(int memberNumber, int selectedYear)
        {
            var content = await _apiClient
                                    .MemberPdfAsync(memberNumber, selectedYear)
                                    .ConfigureAwait(false);
            if (content.HasPdf)
            {
                    return this.File(content.Pdf, "application/pdf", $"Statement{selectedYear}_{DateTime.Now:yyyyMMdd}_{DateTime.Now:HHmmss}.pdf");
            }
    
            var nodeId = this.CurrentPage.Id; ------ERRORS HERE
           ...
        }
    }
    

    }

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Sep 07, 2018 @ 11:07
    Alex Skrypnyk
    0

    Hi Mike

    Try to use:

    var nodeId = Umbraco.AssignedContentItem.Id;
    

    Alex

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Sep 07, 2018 @ 11:15
    Alex Skrypnyk
    0

    What version of Umbraco are you using?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Sep 11, 2018 @ 15:40
    Alex Skrypnyk
    0

    Hi Mike

    Did you solve this issue? Can you share with our community?

    Alex

Please Sign in or register to post replies

Write your reply to:

Draft