I have created a custom admin grid and an associated form in magento 2. While saving a item the success message is not displayed. Do I need any special component in grid to add success message in my save controller Or do I need to inject message manager interface. If this shouldn't be happening please provide me with a solution, thanks Save.php


use X\Y\Model\BannerFactory;

class Save extends \Magento\Backend\App\Action

    protected $_model;
    protected $_resultRedirectFactory;
    protected $_authSession;
    public function __construct(
    \Magento\Backend\App\Action\Context $context, BannerFactory $model, \Magento\Backend\Model\View\Result\RedirectFactory $resultRedirectFactory, \Magento\Backend\Model\Auth\Session $authSession
        $this->_model = $model;
        $this->_resultRedirectFactory = $resultRedirectFactory;
        $this->_authSession = $authSession;

    public function execute()
        $id = $this->getRequest()->getParam('id');
        try {
            $modelData = $this->_model->create();
            //If gets id loads the model
            if ($id) {
                $modelData = $modelData->load($id);

            $formData = $this->getRequest()->getParam('general');
            $imageData = $this->getRequest()->getParam('upload');

            $user = $this->getCurrentUser();

            if (empty($formData ['id'])) {

                $formData['id'] = null;
                // update the current user name for both created and updated
                $formData['created_by'] = $user;
                $formData['updated_by'] = $user;

            $formData['updated_by'] = $user;
            //For small image
            if (isset($imageData['small_image'])) {
                $formData['small_image'] = $imageData['small_image'][0]['name'];

            //Set all the data in DB from form
            $this->messageManager->addSuccess(__("Your Slide has been saved !"));
        } catch (Exception $e) {
        //Result redirected to index controller     
        $resultRedirect = $this->_resultRedirectFactory->create()->setPath('*/*/index');
        return $resultRedirect;

    public function getCurrentUser()
    { //Get the current user name using session
        return $this->_authSession->getUser()->getUsername();


1 Answer 1


If your controller extends \Magento\Backend\App\Action I believe this should work, before doing the redirect

$this->messageManager->addSuccess(__('Your success message here'));


$this->getMessageManager()->addSuccess(__('Your success message here'));

Update: It could be a layout problem then. More info https://magento.stackexchange.com/a/127689/3566

  • I am adding messge in above manner only. I need to show this message in grid page.
    – Jaisa
    Commented Feb 8, 2018 at 4:35
  • Answer updated, it seems layout problem Commented Feb 8, 2018 at 7:49
  • @RaulSanchez how to show success message in Custom Model page ? Commented May 30, 2018 at 9:39
  • I think you'd add a new question for that @Aditya Commented May 30, 2018 at 11:09
  • Yes sure i am adding a question for that and sending you the url :) if you are aware about then please answer Commented May 30, 2018 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.