1

I'm using EPiServer 7.7 MVC and have a scenario where I have a local / global Block MyBlock. MyBlock has a controller MyBlockController. I need to get the ID of the page that invoked MyBlockController:

 public class MyBlockController : BlockController<MyBlock>{

      public override ActionResult Index(MyBlock currentContent){
          Guid hostingPageId = ????
      }
  }

I've looked through the BlockData and ContentData classes but they don't seem to have any references to hosts.

Can I get the current page's id from the controller context perhaps?

BU0
  • 609
  • 2
  • 10
  • 20
Philip Pittle
  • 11,821
  • 8
  • 59
  • 123

1 Answers1

3

EPiServer has the PageRouteHelper for exactly this purpose.
It has a property Page that returns the current Page for the current request context.

So your code would become:

public class MyBlockController : BlockController<MyBlock>
{
    private readonly PageRouteHelper _pageRouteHelper;

    public override ActionResult Index(MyBlock currentContent)
    {
        Guid hostingPageId = _pageRouteHelper.Page.PageGuid;
    }
}
Philip Pittle
  • 11,821
  • 8
  • 59
  • 123