This package is an asp net core mvc toaster notificaton helping tool.
.NET 6 & .NET 7
- Provide dependency Injection
- Ajax request support
- Customizable settings
Install-Package Monirujjaman.AspNetCore.Mvc.Toaster.Notification
Add dependency Injection in the program.cs file Example: builder.Services.AddNotification();
Add middleware in the program.cs file Example: app.UseNotification();
Add the component end of the layout body which layout pages you want to use Example: @await Component.InvokeAsync("Notification")
Setp-1 & Step-2
using Notification.Extensions;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
builder.Services.AddNotification();
var app = builder.Build();
app.UseNotification();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
Setp-3
<!DOCTYPE html>
<html lang="en">
<head>
<title>Title</title>
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true"/>
@await RenderSectionAsync("Links", required: false)
</head>
<body>
@RenderBody()
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
@await Component.InvokeAsync("Notification")
</body>
</html>
using Microsoft.AspNetCore.Mvc;
using Notification.Services.Contracts;
namespace HostelApp.Web.Controllers;
public class HomeController : Controller
{
private readonly INotificationService _notificationService;
public HomeController(INotificationService notificationService)
{ _notificationService = notificationService;
}
public IActionResult Index()
{
_notificationService.Success("My success message", "Success Title!");
_notificationService.Error("My Error message", "Error Title!");
_notificationService.Information("My Information message", "Information Title!");
_notificationService.Warning("My Warning message", "Warning Title!");
return View();
}
}
using Notification.Extensions;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
builder.Services.AddNotification(config =>
{
config.Debug = false;
config.CloseButton = false;
config.ShowEasing = EasingType.Swing;
config.CloseEasing = EasingType.Linear;
config.HideEasing = EasingType.Linear;
config.ShowMethod = AnimationMethod.SlideDown;
config.HideMethod = AnimationMethod.SlideUp;
config.CloseMethod = AnimationMethod.SlideUp;
config.PositionClass = NotificationPosition.TopRight;
config.PreventDuplicates = false;
config.ProgressBar = true;
config.NewestOnTop = false;
config.TimeOutInSecond = 5;
});
var app = builder.Build();
app.UseNotification();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();