I have create admin sales grid. All is working fine. And i have added one link in order view page. This link click redirect custom admin form. And Finally i want to save custom admin form. And redirect order view page backurl
View edit link in order view section :-
And then click edit link go to custom admin form.And custom admin form save after redirect order view page.
Order view page URL :- http://127.0.0.1/mag233/admin/sales/order/view/order_id/2/
Custom admin form URL :- http://127.0.0.1/mag233/admin/editfrom/index/index/order_id/2/
And then custom admin form save after come back order view page.
Here is my save controller code :-
<?php
namespace LR\Adminsalesgrid\Controller\Adminhtml\Index;
use Magento\Backend\App\Action;
use LR\Adminsalesgrid\Model\Lr;
use \Magento\Framework\Controller\ResultFactory;
class Save extends \Magento\Backend\App\Action
{
protected $Custommodel;
public function __construct(
Action\Context $context,
Lr $Custommodel
) {
parent::__construct($context);
$this->Custommodel = $Custommodel;
}
public function execute()
{
$data = $this->getRequest()->getPostValue();
if ($data) {
$id = $this->getRequest()->getParam('id');
if ($id) {
$this->Custommodel->load($id);
}
$this->Custommodel->setData($data);
try {
$this->Custommodel->save();
$this->messageManager->addSuccess(__('The data has been saved.'));
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
$resultRedirect->setUrl($this->_redirect->getRefererUrl());
return $resultRedirect;
}catch (\Exception $e) {
$this->messageManager->addException($e, __('Something went wrong while saving the data.'));
}
return $resultRedirect->setPath('*/*/edit', ['id' => $this->getRequest()->getParam('id')]);
}
return $resultRedirect->setPath('*/*/');
}
}
Please advice me what is actually problem.
THANKS.