Please provide an example of a toast notification that can changed from the controller (POST)

Hello,

I am having some challenges using the Toast control within my ASP.NET Core app.

Could you provide a simple example of a Toast implementation where:

1/ the toast will be hidden by default when calling view ABC (GET)

2/ User clicks on button on view ABC to trigger POST version of same action ABC

3/ In ABC action (POST) in controller :

- Toast is setup with message "Error" if error in processing

- Toast is setup with message "Success" if no error

- view ABC is returned

4/ Toast message is shown in view ABC with relevant message (either "Error" or "Success" as per logic in controller (POST ABC))

Thank you.


5 Replies

IS Indrajith Srinivasan Syncfusion Team July 29, 2021 01:17 PM UTC

Hi Loic, 
 
Greetings from Syncfusion support, 
 
We have validated your reported query with the shared information. We have prepared a sample meeting your requirements,  by showing the toast control (success & error) base on the controller action return. Check the below shared sample for reference. 
 
In the below sample the following are configured, 
  • Ajax request for controller call.
  • Buttons to send the post request.
  • Based on the controller action return, the toast is opened.
 
Can you please check the above sample, and let us know if it meets your requirements ? 
 
Regards, 
Indrajith 



LR Loic Roger July 29, 2021 07:02 PM UTC

Thanks for the quick feedback.

I was hoping for an example without using AJAX/javascript, potentially leveraging ViewData that would be set in the controller and having the Toast show the specific message (Error/Success) using ViewData when the view is returned from the POST action.

Is this possible ?

Thanks,




GK Gunasekar Kuppusamy Syncfusion Team July 30, 2021 12:45 PM UTC

Hi Loic,


Greetings from Syncfusion support.


We have validated your reported query. We can achieve your requirement by using ViewBag in Controller.

We have prepared a sample for your reference. In the below sample we have updated the toast content and CSS class to the ViewBag based on the result and rendered toast based on that updated value.

Code snippets:
<ejs-toast id="element" created="oncreated" content="@ViewBag.content" cssClass="@ViewBag.css">
</ejs-toast>

Controller:
 public IActionResult Index()
        {
            var result = true;         
            if (result)
            {
                ViewBag.content = "Success Message";
                ViewBag.css = "e-toast-success";
            } else
            {
                ViewBag.content = "Failure Message";
                ViewBag.css = "e-toast-danger";
            }
            return View();
        }


Please check the sample and let you know if the solution meets your requirement.

Regards,
Gunasekar K


LR Loic Roger July 30, 2021 01:50 PM UTC

thank you.



GK Gunasekar Kuppusamy Syncfusion Team August 2, 2021 12:48 PM UTC

 Hi Loic, 

 

 
Thanks for the update.  
We are glad that the provided solution resolved the issue. Please let us know if you need further assistance.  
  
Regards,  
Gunasekar 


Loader.
Up arrow icon