magento2 – Magento 2 how to redirect backend controller to previous page?

I’m trying to redirect a controller that is executed in Order Detail.

If I end the controller returning redirect like this, it throws an error:

return $resultRedirect;

If I end the controller with exit; it does not throws error but a blank page is displayed.


Here is my code:


use MagentoBackendAppAction;
use MagentoFrameworkAppRequestInterface;
use VendorModuleLoggerLogger;
use MagentoSalesApiOrderRepositoryInterface;

class Pdf extends Action
     * @var PageFactory
    protected $request;
    protected $logger;
    protected $orderRepository;
    protected $resultRedirectFactory;
     * @param Context $context
     * @param PageFactory $resultPageFactory

    public function __construct(
        RequestInterface $request,
        Logger $logger,
        OrderRepositoryInterface $orderRepository,
        MagentoFrameworkControllerResultFactory $resultRedirectFactory,
        MagentoBackendAppAction $context
    ) {
        $this->request = $request;
        $this->logger = $logger;
        $this->orderRepository = $orderRepository;
        $this->resultRedirectFactory = $resultRedirectFactory;
     * Index action
     * @return MagentoBackendModelViewResultPage
    public function execute()
        $completeState = MagentoSalesModelOrder::STATE_COMPLETE;

        $order_id = $this->request->getParam('order_id');
            $order = $this->orderRepository->get($order_id);

            $resultRedirect = $this->resultRedirectFactory->create(MagentoFrameworkControllerResultFactory::TYPE_REDIRECT);
            return $resultRedirect;