All Projects → nabinked → Ntoastnotify

nabinked / Ntoastnotify

Licence: mit
Asp.Net Core abstraction for server side rendered toast notifications using toast.js or noty.js. Supports AJAX calls as well.

Projects that are alternatives of or similar to Ntoastnotify

Rapidcms
RapidCMS is a Blazor framework which allows you to build a responsive and flexible CMS purely from code. It provides a basic set of editors and controls, and is fully customisable.
Stars: ✭ 149 (+17.32%)
Mutual labels:  asp-net-core, server-side
ajxnetcore
Its an innovative method to turn an ASP.NET Core Application Into Single Page Application, While enhancing the Software performance both on server and client side.
Stars: ✭ 31 (-75.59%)
Mutual labels:  ajax, asp-net-core
AspNetCore.Unobtrusive.Ajax
Unobtrusive Ajax Helpers (like MVC5 Ajax.BeignForm and Ajax.ActionLink) for ASP.NET Core
Stars: ✭ 46 (-63.78%)
Mutual labels:  ajax, asp-net-core
Fanray
A blog built with ASP.NET Core
Stars: ✭ 117 (-7.87%)
Mutual labels:  asp-net-core
Django Crud Ajax Login Register Fileupload
Django Crud, Django Crud Application, Django ajax CRUD,Django Boilerplate application, Django Register, Django Login,Django fileupload, CRUD, Bootstrap, AJAX, sample App
Stars: ✭ 118 (-7.09%)
Mutual labels:  ajax
Sio.core
✔ [ SIOC ] Swastika I/O Core is an all in one platform (e.g CMS, eCommerce, Forum, Q&A, CRM...) ASP.NET Core / Dotnet Core System based on SIOH Framework.
Stars: ✭ 121 (-4.72%)
Mutual labels:  asp-net-core
Aspnetcorehybridflowwithapi
ASP.NET Core MVC application using API, OpenID Connect Hybrid flow , second API, Code Flow with PKCE
Stars: ✭ 127 (+0%)
Mutual labels:  asp-net-core
Fetch Plus
🐕 Fetch+ is a convenient Fetch API replacement with first-class middleware support.
Stars: ✭ 116 (-8.66%)
Mutual labels:  ajax
Sente
Realtime web comms for Clojure/Script
Stars: ✭ 1,626 (+1180.31%)
Mutual labels:  ajax
Aspnetcore Dockerswarm
ASP.NET Core orchestration scenarios with Docker
Stars: ✭ 120 (-5.51%)
Mutual labels:  asp-net-core
Vue2 Bootstrap Table
A sortable and searchable table, as a Vue2 component, using bootstrap styling.
Stars: ✭ 120 (-5.51%)
Mutual labels:  ajax
Pixelwave
Fully customizable pixel wave animation for seamless page transitions.
Stars: ✭ 119 (-6.3%)
Mutual labels:  ajax
Recaptcha.aspnetcore
Google reCAPTCHA v2/v3 for .NET Core 3.x
Stars: ✭ 122 (-3.94%)
Mutual labels:  asp-net-core
Odatatoentity
OData .net core
Stars: ✭ 117 (-7.87%)
Mutual labels:  asp-net-core
Scrutor
Assembly scanning and decoration extensions for Microsoft.Extensions.DependencyInjection
Stars: ✭ 1,915 (+1407.87%)
Mutual labels:  asp-net-core
Recaptcha Net
reCAPTCHA for .NET library lets you easily use Google's reCAPTCHA in an ASP.NET Web Forms / MVC / ASP.NET Core application.
Stars: ✭ 116 (-8.66%)
Mutual labels:  asp-net-core
Ajax Hook
🔱 Intercepting browser's AJAX requests which made by XMLHttpRequest.
Stars: ✭ 1,900 (+1396.06%)
Mutual labels:  ajax
Csharp Datatables Parser
C# Serverside parser for the popuplar jQuery datatables plugin.
Stars: ✭ 119 (-6.3%)
Mutual labels:  asp-net-core
Ajax Panel
Ajax Panel Plugin for Grafana
Stars: ✭ 119 (-6.3%)
Mutual labels:  ajax
Yii2fullcalendar
JQuery Fullcalendar Yii2 Extension
Stars: ✭ 120 (-5.51%)
Mutual labels:  ajax

Build Status

Features

  • Server side toast notification rendering.
  • Toast notification on AJAX calls. XMLHTTPRequests - Full Support. fetch API - Partial Support (See sample).
  • Supports Feature folder project structure.
  • Supports multiple client libraries: toastr.js & noty.js. Can easily be extended to support more.

DEMOs

Get Started

1. Install From Nuget

Visual Studio Nuget Package Manager - Install-Package NToastNotify

dotnet CLI - dotnet add package NToastNotify

2. Add NtoastNotify to the ASP.NET Core Services. Use the extension method on IMVCBuilder or IMVCCoreBuilder

  • For Toastr.js [Note: toastr library depends on jQuery]

    using NToastNotify.Libraries;
    
    
    services.AddMvc().AddNToastNotifyToastr(new ToastrOptions()
    {
                ProgressBar = false,
                PositionClass = ToastPositions.BottomCenter
    });
    
    //Or simply go 
    services.AddMvc().AddNToastNotifyToastr();
    
  • For Noty.js

    using NToastNotify.Libraries;
    
    services.AddMvc().AddFeatureFolders().AddNToastNotifyNoty(new NotyOptions {
                    ProgressBar = true,
                    Timeout = 5000,
                    Theme = "mint"
                });
    
    //Or Simply go
    services.AddMvc().AddNToastNotifyNoty();
    

Note: Make sure you have the necessary using statements.

The ToastrOption parameter acts as the global options for the toast library. If no options are provided the global settings will be the default toastr options.

3. Add the middleware

 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
 {
        //NOTE this line must be above .UseMvc() line.
        app.UseNToastNotify();
        
        app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
 }

4. Add the following line in your html file. Preferably in your Layout Page.

@await Component.InvokeAsync("NToastNotify")

The above line renders the View necessary for the view component. Although you can place this line anywhere inside your head or body tag, It is recommended that you place this line at the end before the closing body tag.

5. Add your toast messages.

using toastr

public class HomeController : Controller
    {
        private readonly IToastNotification _toastNotification;

        public HomeController(IToastNotification toastNotification)
        {
            _toastNotification = toastNotification;
        }
        public IActionResult Index()
        {
            //Testing Default Methods

            //Success
            _toastNotification.AddSuccessToastMessage("Same for success message");
            // Success with default options (taking into account the overwritten defaults when initializing in Startup.cs)
            _toastNotification.AddSuccessToastMessage();

            //Info
            _toastNotification.AddInfoToastMessage();

            //Warning
            _toastNotification.AddWarningToastMessage();

            //Error
            _toastNotification.AddErrorToastMessage();

            return View();
        }

        public IActionResult About()
        {
            _toastNotification.AddInfoToastMessage("You got redirected");
            return View();
        }

        public IActionResult Contact()
        {
            _toastNotification.AddAlertToastMessage("You will be redirected");
            return RedirectToAction("About");
        }

        public IActionResult Error()
        {
            _toastNotification.AddErrorToastMessage("There was something wrong with this request.");
            return View();
        }

        public IActionResult Empty()
        {

            return View();
        }

        public IActionResult Ajax()
        {
            _toastNotification.AddInfoToastMessage("This page will make ajax requests and show notifications.");
            return View();
        }

        public IActionResult AjaxCall()
        {
            System.Threading.Thread.Sleep(2000);
            _toastNotification.AddSuccessToastMessage("This toast is shown on Ajax request. AJAX CALL " + DateTime.Now.ToLongTimeString());
            return PartialView("_PartialView", "Ajax Call");
        }

        public IActionResult NormalAjaxCall()
        {
            return PartialView("_PartialView", "Normal Ajax Call");
        }

        public IActionResult ErrorAjaxCall()
        {
            throw new Exception("Error occurred");
        }
    }

using noty (basically the same thing only thing that changes is the options type, here its NotyOptions)


public class HomeController : Controller
    {
        private readonly IToastNotification _toastNotification;

        public HomeController(IToastNotification toastNotification)
        {
            _toastNotification = toastNotification;
        }
        public IActionResult Index()
        {
            _toastNotification.AddSuccessToastMessage();
            _toastNotification.AddErrorToastMessage("Test Erro", new NotyOptions()
            {
                Timeout = 0
            });
            return View();
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";
            _toastNotification.AddAlertToastMessage("My About Warning Message");
            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";
            _toastNotification.AddInfoToastMessage("Dont get confused. <br /> <strong>You were redirected from Contact Page. <strong/>");
            return RedirectToAction("About");
        }

        public IActionResult Error()
        {
            _toastNotification.AddErrorToastMessage("There was something wrong with this request.");

            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }

        public IActionResult Ajax()
        {
            _toastNotification.AddInfoToastMessage("This page will make ajax requests and show notifications.");
            return View();
        }

        public IActionResult AjaxCall()
        {
            System.Threading.Thread.Sleep(2000);
            _toastNotification.AddSuccessToastMessage("This toast is shown on Ajax request. AJAX CALL " + DateTime.Now.ToLongTimeString());
            return PartialView("_PartialView", "Ajax Call");
        }

        public IActionResult NormalAjaxCall()
        {
            return PartialView("_PartialView", "Normal Ajax Call");
        }

        public IActionResult ErrorAjaxCall()
        {
            throw new Exception("Error occurred");
        }
    }

Possible Issue

  • Toast not shown after POST-REDIRECT

FIX If you are using CookieTempDataProvider (this is the default) you need to accept cookie policy prompt.

Become a patreon

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].