Skip to content

upretymadan45/NetCoreClientNotifications

Repository files navigation

NetCoreClientNotifications

Give feedback to client in your asp net core 2 and above mvc application using client side javascript notifications : toastr and sweet js

Installation

From Dotnet CLI

  • dotnet add package ClientNotifications --version 1.17.1

From Package Manager

  • Install-Package ClientNotifications -Version 1.17.1

Add Client side javascript and css file:

Usage:

Add the following to your startup.cs file

  • services.AddToastNotification();

  • Inject IClientNotification to your controller

            private IClientNotification _clientNotification;
    
            public HomeController(IClientNotification clientNotification)
            {
                _clientNotification = clientNotification;
            }
    
  • Create Toast Notification as follows

      _clientNotification.AddToastNotification("From Index of home",
                                              NotificationType.success,
                                              new ToastNotificationOption{
                                                  ProgressBar = true,
                                                  PositionClass ="toast-bottom-right"
                                              });
    

OR

    _clientNotification.AddToastNotification("From Index of home",
                                            NotificationType.success,
                                            null);
  • Create Sweet Notifications as follows

    _clientNotification.AddSweetNotification("Good",
                                      "You have got a success",
                                      NotificationType.success);
    
  • Add the following line to your layout file

    • @await Component.InvokeAsync("ClientNotifications.Notify")