Giter Site home page Giter Site logo

nabinked / ntoastnotify Goto Github PK

View Code? Open in Web Editor NEW
195.0 10.0 54.0 2.21 MB

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

License: MIT License

C# 83.38% TypeScript 14.30% JavaScript 1.24% HTML 1.07%
asp-net-core toast-notifications server-side ajax toastr noty

ntoastnotify's Introduction

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.

Running the repo locally

  • npm install
  • npm build
  • dotnet restore
  • dotnet build

Run any sample project using dotnet run from sample project dir

ntoastnotify's People

Contributors

davidfowl avatar dependabot[bot] avatar devbrsa avatar dkolarev avatar eopeter avatar gfulep avatar jciechowski avatar jerriep avatar kiapanahi avatar leniel avatar lvmajor avatar mathiaskowoll avatar nabinked avatar vixero-dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ntoastnotify's Issues

Error when text contains single quotes (apostrophe)

As the title says, the generated toast notification fails to render correctly if text contains any single quote (which are pretty common in French language) -> similar problem as outlined in #22, could close this one in favor of the former.

Would it be a big problem switching to double quotes for string delimiter?

JavaScript handles it perfectly when text within double quotes contains single quotes.

Thanks in advance!

After adding AddSessionStateTempDataProvider to my MVC configuration I get an InvalidOperationException

After adding .AddSessionStateTempDataProvider() to my MVC configuration I get the following exception:

InvalidOperationException: Session has not been configured for this application or request.
Microsoft.AspNetCore.Http.DefaultHttpContext.get_Session()
Microsoft.AspNetCore.Mvc.ViewFeatures.SessionStateTempDataProvider.LoadTempData(HttpContext context)
Microsoft.AspNetCore.Mvc.ViewFeatures.TempDataDictionary.Load()
Microsoft.AspNetCore.Mvc.ViewFeatures.TempDataDictionary.ContainsKey(string key)
NToastNotify.TempDataWrapper.Peek<T>(string key)
NToastNotify.MessageContainers.TempDataMessageContainer<TMessage>.GetAll()
NToastNotify.MessageContainers.TempDataMessageContainer<TMessage>.ReadAll()
NToastNotify.ToastNotification<TMessage, TOptions>.ReadAllMessages()
NToastNotify.NToastNotifyViewComponent.Invoke()
lambda_method(Closure , object , object[] )
Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(object target, object[] parameters)
Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker.InvokeSyncCore(ObjectMethodExecutor executor, ViewComponentContext context)
Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker.InvokeAsync(ViewComponentContext context)
StackExchange.Profiling.Internal.ProfilingViewComponentInvoker.InvokeAsync(ViewComponentContext context) in ProfilingViewComponentInvoker.cs
Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentHelper.InvokeCoreAsync(ViewComponentDescriptor descriptor, object arguments)
AspNetCore.Views_Shared__Layout+<>c__DisplayClass53_0+<<ExecuteAsync>b__1>d.MoveNext() in _Layout.cshtml
+
    @await Component.InvokeAsync("NToastNotify")

I did configure the session (sevices.AddSession() and app.UseSesssion()), so not sure why this exception occurs.

app.UseSession is called before app.UseMvc and also before app.UseNToastNotify

InvalidOperationException: Cannot find compilation library location for package 'Microsoft.Win32.Registry'

I have this issue after publish. No problem working at localhost.
I already tried the solution from a related post (#21) but it's not working for me.

Exception from app insights
System.InvalidOperationException:
at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths (Microsoft.Extensions.DependencyModel, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths (Microsoft.Extensions.DependencyModel, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.Mvc.ApplicationParts.AssemblyPart+<>c.b__8_0 (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Linq.Enumerable+SelectManySingleSelectorIterator2.MoveNext (System.Linq, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a) at Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeatureProvider.PopulateFeature (Microsoft.AspNetCore.Mvc.Razor, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorReferenceManager.GetCompilationReferences (Microsoft.AspNetCore.Mvc.Razor, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Threading.LazyInitializer.EnsureInitializedCore (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorReferenceManager.get_CompilationReferences (Microsoft.AspNetCore.Mvc.Razor, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Mvc.Razor.Internal.LazyMetadataReferenceFeature.get_References (Microsoft.AspNetCore.Mvc.Razor, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.CodeAnalysis.Razor.CompilationTagHelperFeature.GetDescriptors (Microsoft.CodeAnalysis.Razor, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Razor.Language.DefaultRazorTagHelperBinderPhase.ExecuteCore (Microsoft.AspNetCore.Razor.Language, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Razor.Language.RazorEnginePhaseBase.Execute (Microsoft.AspNetCore.Razor.Language, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Razor.Language.DefaultRazorEngine.Process (Microsoft.AspNetCore.Razor.Language, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine.GenerateCode (Microsoft.AspNetCore.Razor.Language, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CompileAndEmit (Microsoft.AspNetCore.Mvc.Razor, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CreateCacheEntry (Microsoft.AspNetCore.Mvc.Razor, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorPageFactoryProvider.CreateFactory (Microsoft.AspNetCore.Mvc.Razor, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.CreateCacheResult (Microsoft.AspNetCore.Mvc.Razor, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.OnCacheMiss (Microsoft.AspNetCore.Mvc.Razor, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.LocatePageFromViewLocations (Microsoft.AspNetCore.Mvc.Razor, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.FindView (Microsoft.AspNetCore.Mvc.Razor, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Mvc.ViewEngines.CompositeViewEngine.FindView (Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Mvc.ViewComponents.ViewViewComponentResult+<ExecuteAsync>d__20.MoveNext (Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker+<InvokeAsync>d__5.MoveNext (Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentHelper+<InvokeCoreAsync>d__12.MoveNext (Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at AspNetCore._Views_Shared__Layout_cshtml+<b__52_9>d.MoveNext (MercadoPagoAdm.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nullMercadoPagoAdm.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: C:\Projects\Aoniken\MercadoPago\MercadoPago\MercadoPagoAdm\Views\Shared_Layout.cshtmlMercadoPagoAdm.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: 100)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext+d__30.MoveNext (Microsoft.AspNetCore.Razor.Runtime, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at AspNetCore._Views_Shared__Layout_cshtml+d__52.MoveNext (MercadoPagoAdm.PrecompiledViews, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.Razor.RazorView+d__16.MoveNext (Microsoft.AspNetCore.Mvc.Razor, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.Razor.RazorView+d__15.MoveNext (Microsoft.AspNetCore.Mvc.Razor, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.Razor.RazorView+d__18.MoveNext (Microsoft.AspNetCore.Mvc.Razor, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.Razor.RazorView+d__14.MoveNext (Microsoft.AspNetCore.Mvc.Razor, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor+d__22.MoveNext (Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor+d__21.MoveNext (Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.ViewResult+d__26.MoveNext (Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__19.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__24.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__22.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__17.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__15.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Builder.RouterMiddleware+d__4.MoveNext (Microsoft.AspNetCore.Routing, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at NToastNotify.NtoastNotifyAjaxToastsMiddleware+d__5.MoveNext (NToastNotify, Version=5.0.7.0, Culture=neutral, PublicKeyToken=null)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions+<>c__DisplayClass5_1+<b__1>d.MoveNext (Microsoft.AspNetCore.Http.Abstractions, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+d__6.MoveNext (Microsoft.AspNetCore.Authentication, Version=2.0.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware+d__6.MoveNext (Microsoft.AspNetCore.Diagnostics, Version=2.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)

Enhancement request: Make wrapper functions to ease the sending of Error, success messages

It could be nice to have some wrapper functions that lets us publish a notification without needing to specify the type of it.

For example, instead of calling the plugin this way:

_toastNotification.AddToastMessage("Success Title", "My Warning Message", ToastEnums.ToastType.Warning, new ToastOption()
{
    PositionClass = NToastNotify.Constants.ToastPositions.BottomFullWidth
});

It would be nice to have an option to call it like this:

_toastNotification.AddWarningMessage("Warning title", "My warning message"); // Here I let the default options 

You get the idea, tell me if you think that would be a good addition to the library and I'll try to see if I could implement it in the following days.

Show message after ajax redirect?

Hi, is it possible to show message if I redirect to action from ajax. Here is the code:

C# code
publicIActionResult Ajax() { toastNotification.AddSuccessToastMessage(TextResource.Info_SaveSuccess); return this.Ok(new { redirect = true, url = "/User/EditProfile" }); }
JS code
$.ajax({ url: $this.attr('action'), type: 'post', data: formData, dataType: 'json', statusCode: { 200: function (data) { if (data.redirect) { if (data.url) { window.location = data.url; } else { window.scrollTo(0, 0); window.location.reload(); } } } },

Make AJAX Toasts optional

Since Ajax toasts uses custom request/response headers for message transportation it may be problematic in some cases where custom headers are restricted. Provide a way to make Ajax toasts optional.

Single quotes in message are not escaped

When we add new toast with a message containing a single quote, the script inserted inside the page fall in error. It can be interresting to add auto escape for support this character.

Toastr Dependency Issue

It seems that when this package was upgraded from 3.0 to 4.0, the dependency for Toastr also got changed.

In 3.0, the code @await Component.InvokeAsync("NToastNotify.Toastr") doesn't create a script that looks for Toastr at that line (which is in the Layout page). So the toastr.js can be loaded at the bottom of the layout page and it would still work without any issues.

In 4.0, this has been changed and now the that template code expects the toastr.js to be available at that line which means that toastr.js has to be included in the header instead of the bottom. Most scripts get loaded at the bottom of the page. So it would be better if this component doesn't force users to load it at the top. If the script generated works exactly as it did with 3.0, then it would be great.

Please look into the matter and update it if you feel my suggestion is appropriate.

Error 500 if toastmessage (text or title) contains characters in another language

That error came only in case of using with partial view. If using with normal view, it works as expected.
Detail error is:

System.InvalidOperationException: Invalid non-ASCII or control character in header: 0x0388
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameHeaders.ThrowInvalidHeaderCharacter(Char ch)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameHeaders.ValidateHeaderCharacters(String headerCharacters)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameHeaders.ValidateHeaderCharacters(StringValues headerValues)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameResponseHeaders.AddValueFast(String key, StringValues value)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameHeaders.System.Collections.Generic.IDictionary<System.String,Microsoft.Extensions.Primitives.StringValues>.Add(String key, StringValues value)
at NToastNotify.NtoastNotifyMiddleware.Callback(Object context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame.d__197.MoveNext()

Tested with some language: CN ("错误已经出现"), VI ("Có lỗi phát sinh"), Greek ("Έχουν προκύψει σφάλματα")
@nabinked Could you support more language? This is awesome!

v.appendTo is not a function

I configured NToastNotify as mentioned in documentation, but I am getting error in browser's console as

Uncaught (in promise) TypeError: v.appendTo is not a function
at d (toastr.js:474)
at n (toastr.js:474)
at g (toastr.js:474)
at Object.i [as success] (toastr.js:474)
at t.showMessage (toastr.js?v=201806070714:1)
at toastr.js?v=201806070714:1
at Array.forEach ()
at t.e.showMessages (toastr.js?v=201806070714:1)
at t. (toastr.js?v=201806070714:1)
at toastr.js?v=201806070714:1
d @ toastr.js:474
n @ toastr.js:474
g @ toastr.js:474
i @ toastr.js:474
t.showMessage @ toastr.js?v=201806070714:1
(anonymous) @ toastr.js?v=201806070714:1
e.showMessages @ toastr.js?v=201806070714:1
(anonymous) @ toastr.js?v=201806070714:1
(anonymous) @ toastr.js?v=201806070714:1
(anonymous) @ toastr.js?v=201806070714:1
i @ toastr.js?v=201806070714:1
Promise.then (async)
u @ toastr.js?v=201806070714:1
(anonymous) @ toastr.js?v=201806070714:1
o @ toastr.js?v=201806070714:1
e.domContentLoadedHandler @ toastr.js?v=201806070714:1

Let me know if I am doing something wrong or you need more information.

Viewcomponent Error

I invoked the viewcomponent in the layout page and i get 404 error on all other pages only on deployment to azure

View Component not resolving

I cannot seem to get the View Component to resolve when I add thwe foolowing line of code to the bottom of the body tag in my layout page.

@await Component.InvokeAsync("NToastNotify")

The string "NToastNotify" stays read and I get an error message saying

cannot resolve view component

Error 404 with /NToastNotify/js/dist/toastr.js.map

I getting this error is some occasions... it can't find the .map file!
The funny topic here is that i don't have this directory on my solution... i have other '\wwwroot\vendors\bower_components\toastr'.

Any ideas?

{
"name": "Microsoft.ApplicationInsights.Dev.Request",
"time": "2018-02-27T14:19:22.1554123Z",
"tags": {
"ai.internal.sdkVersion": "aspnet5c:2.1.1",
"ai.application.ver": "3.4.0.0",
"ai.internal.nodeName": "DESKTOP-DEV",
"ai.location.ip": "::1",
"ai.cloud.roleInstance": "DESKTOP-DEV",
"ai.operation.name": "GET /NToastNotify/js/dist/toastr.js.map",
"ai.operation.id": "1176b267-400a63c996f478ff"
},
"data": {
"baseType": "RequestData",
"baseData": {
"ver": 2,
"id": "|1176b267-400a63c996f478ff.",
"name": "GET /NToastNotify/js/dist/toastr.js.map",
"duration": "00:00:00.0007341",
"success": false,
"responseCode": "404",
"url": "https://localhost:44379/NToastNotify/js/dist/toastr.js.map",
"properties": {
"httpMethod": "GET",
"AspNetCoreEnvironment": "Development",
"DeveloperMode": "true"
}
}
}
}

Regards,

Issue with ajax call

When I execute an ajax call everything seems to work fine, but when it should run the function success or error doesn't work.
When I debbug it in Chrome, the request show thats the "Initiator" was toastr.js, nevertheless in this part of my code I don´t call a toast.
I've been researching and it seems that toast.js is intercepting all xml request so I want to know if this could be the cause of my Issue

Ajax call - TypeError: response.headers is undefined

Hi there,

I have the following ajax call:

$.ajax({
                            url:  'some-url',
                            //dataType: 'json',
                            type: 'POST',
                            data: data,
                            async: true,
                            cache: false,
                            headers: {
                                'X-XSRF-TOKEN': serviceEndpoints.xsrfToken
                            }
                        })
                        .done(function (result, textStatus, jqXHR) {
	                        var messages = window.nToastNotify.getMessagesFromFetchResponse(result);
	                        window.nToastNotify.showMessages(messages);
                        }); 
[HttpPost("[action]"]
        public async Task<IActionResult> DeleteFoo(int id)
        {
                      
            var result = await _service.DeleteFoo(id);

            _toastNotification.AddSuccessToastMessage("Foo Deleted", new ToastrOptions
            {
                Title = "Success",
                CloseButton = true,
                CloseOnHover = false,
                PositionClass = ToastPositions.BottomFullWidth,
                PreventDuplicates = true,
                ShowMethod = "slideDown",
            });

            return Content("AJAX");
            //return Ok(Json(result));
        }

The ajax call runs fine, I see the toastr pop up but I see an error in the browser console:
TypeError: response.headers is undefined

It's complaining about the following code:

NToastNotify.prototype.getMessagesFromFetchResponse = function (response) {
        var messageStr = response.headers.get(this.options.responseHeaderKey);
        if (messageStr) {
            return JSON.parse(messageStr);
        }
        else {
            return null;
        }
    };

UPDATE
It seems the error is caused because I was calling
var messages = window.nToastNotify.getMessagesFromFetchResponse(result); window.nToastNotify.showMessages(messages);

If I remove these lines, the toastr still comes up so not sure what's happening in regards to ajax calls, I thought I would have to use the above lines for the toastr to work?

Can't see Toastr notifications on all return IActionResult actions except Ok actionresult

Hi,
I'm having some issues with NToastNotify.
I only seem to be able to get Toastr notifications if I return a Ok object.
I've tried returning other objects such as View and CreateAtRoute but they don't seem to work.

I'm using 1.0.6 of NToastNotify as I assume any higher versions require version 2 or higher of .NET Core.

Here's one of my functions that use NToastNotify

        [HttpPost]
        public IActionResult Create([FromBody] ConfiguredProcess item)
        {
            if (item == null)
            {
                _toastNotification.AddToastMessage("Process Config Creation", "Blank Process details passed", ToastEnums.ToastType.Error);
                return BadRequest();
            }

            try
            {
                item.Id = 0;
                _repository.Add(item);
                _toastNotification.AddToastMessage("Process Config Creation", "Process Config created successfully",
                    ToastEnums.ToastType.Success);
                //return CreatedAtRoute("GetWorkflow", new { id = item.Id }, item); //Doesn't work for Toastr
                return Ok(Json(item));    //Works
                //return View("Index");     // Doesn't work for Toastr
                //return View();            // Doesn't work for Toastr
            }
            catch (Exception ex)
            {
                _toastNotification.AddToastMessage("Process Config Creation Error", ex.ToString(), ToastEnums.ToastType.Error);
                return StatusCode(StatusCodes.Status500InternalServerError, ex);
            }

        }

What could I be doing wrong or have I set up NToastNotify incorrectly?

            // ToastNotify() has to be above AddMvc()
            services.AddNToastNotify(new ToastOption()
            {
                ProgressBar = false,
                PositionClass = ToastPositions.BottomCenter
            });

            // Add framework services.
            services.AddMvc();

As a test, I've included the following JS on my index.cshtml to prove that verify toastr is up and running.

    <script>
        $(function () { //ready
            toastr.info('If all three of these are referenced correctly, then this should toast should pop-up.');
        });
    </script>

InvalidOperationException: Cannot find compilation library location for package 'Microsoft.Win32.Registry'

I am getting this error on two different servers. This is not happening in my local setup however. After playing around with the code I figured it out that this is only happening on the views where I have added

@await Component.InvokeAsync("NToastNotify.Toastr")

commenting this line of code works. But Off course toastr stops working.
I have ASP.net core 2.0 mvc application running in Windows Server 2012 R2 in IIS 8

An unhandled exception occurred while processing the request.

InvalidOperationException: Cannot find compilation library location for package 'Microsoft.Win32.Registry'
Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver resolver, List assemblies)

Stack

Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver resolver, List assemblies)
Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()
Microsoft.AspNetCore.Mvc.ApplicationParts.AssemblyPart+<>c.b__8_0(CompilationLibrary library)
System.Linq.Enumerable+SelectManySingleSelectorIterator.MoveNext()
Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeatureProvider.PopulateFeature(IEnumerable parts, MetadataReferenceFeature feature)
Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateFeature(TFeature feature)
Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorReferenceManager.GetCompilationReferences()
System.Threading.LazyInitializer.EnsureInitializedCore(ref T target, ref bool initialized, ref object syncLock, Func valueFactory)
Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorReferenceManager.get_CompilationReferences()
Microsoft.AspNetCore.Mvc.Razor.Internal.LazyMetadataReferenceFeature.get_References()
Microsoft.CodeAnalysis.Razor.CompilationTagHelperFeature.GetDescriptors()
Microsoft.AspNetCore.Razor.Language.DefaultRazorTagHelperBinderPhase.ExecuteCore(RazorCodeDocument codeDocument)
Microsoft.AspNetCore.Razor.Language.RazorEnginePhaseBase.Execute(RazorCodeDocument codeDocument)
Microsoft.AspNetCore.Razor.Language.DefaultRazorEngine.Process(RazorCodeDocument document)
Microsoft.AspNetCore.Razor.Language.RazorTemplateEngine.GenerateCode(RazorCodeDocument codeDocument)
Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CompileAndEmit(string relativePath)
Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler.CreateCacheEntry(string normalizedPath)
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorPageFactoryProvider.CreateFactory(string relativePath)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.CreateCacheResult(HashSet expirationTokens, string relativePath, bool isMainPage)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.OnCacheMiss(ViewLocationExpanderContext expanderContext, ViewLocationCacheKey cacheKey)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.LocatePageFromViewLocations(ActionContext actionContext, string pageName, bool isMainPage)
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.FindView(ActionContext context, string viewName, bool isMainPage)
Microsoft.AspNetCore.Mvc.ViewEngines.CompositeViewEngine.FindView(ActionContext context, string viewName, bool isMainPage)
Microsoft.AspNetCore.Mvc.ViewComponents.ViewViewComponentResult+d__20.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker+d__5.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentHelper+d__12.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
AspNetCore._Views_Home_DashBoard_cshtml+d__40.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Razor.RazorView+d__16.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Razor.RazorView+d__15.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
System.Runtime.CompilerServices.TaskAwaiter.GetResult()
Microsoft.AspNetCore.Mvc.Razor.RazorView+d__14.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor+d__22.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor+d__21.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.ViewResult+d__26.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__19.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__24.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__22.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__17.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__15.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Builder.RouterMiddleware+d__4.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+d__6.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware+d__4.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware+d__6.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.DatabaseErrorPageMiddleware+d__6.MoveNext()
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+d__7.MoveNext()

Positining toasts relative to a specific control

im having issues to position toasts on apage. The options presented by ToastPositions are insufficient for me as they seem to be relative to the entire page and not a specific form element.
I tried using ToastrOptions.Target but that doesnt work either. what does that property do?

im trying this on the latest ntoastnotify build with a .net core 2.2 mvc app.

Error with /NToastNotify/js/dist/toastr.js?v=201803200122

Hey there, I don't know if I made a mistake configuring the new version (downloaded v5.0) but it seems like the view component tries to load the toastr.js file from NToastNotify folder but it does not exist within wwwroot so it errors out...

Would you have an idea of what could cause that issue?

Thanks in advance.

XML Parsing Error: no root element found

iam use messge with out quotes .but dont show alert message
when inspect browser this error:XML Parsing Error: no root element found
iam returm msg from sp database.

var Result = _IUserService.UpdatePic(_UplaodImage);
if (Result.Out_Procedure_Result_Status == 0)
_toastNotification.AddErrorToastMessage(Result.Out_Procedure_Result_Status_Message.ToString())

Strange behavior

The first time the notification is requested, it does not appear. From that the notification appears.

Support multiple client libraries?

Right now the library only targets toastr.js for toast notification. May be we could re-design the library to support more libraries such as noty.js /notie.js. Perhaps create a layer of abstraction between the client side library and the library itself. And also make it easier in future to support more libraries.

When i try run aspcore webapp System.Reflection.TypeExtensions .net4.7 vs2017

FileNotFoundException: Не удалось загрузить файл или сборку "System.Reflection.TypeExtensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" либо одну из их зависимостей. Не удается найти указанный файл.

NToastNotify.OptionMerger.MergeWith<T>(T primary, T secondary)
NToastNotify.ToastNotification..ctor(ITempDataWrapper tempDataWrapper, NToastNotifyOption nToastNotifyOptions)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor.VisitCallSite(IServiceCallSite callSite, TArgument argument)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor.VisitCallSite(IServiceCallSite callSite, TArgument argument)
Microsoft.Extensions.DependencyInjection.ServiceProvider+<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
Microsoft.Extensions.Internal.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired)
lambda_method(Closure , IServiceProvider , Object[] )
Microsoft.AspNetCore.Mvc.Internal.TypeActivatorCache.CreateInstance<TInstance>(IServiceProvider serviceProvider, Type implementationType)
Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerActivator.Create(ControllerContext controllerContext)
Microsoft.AspNetCore.Mvc.Controllers.DefaultControllerFactory.CreateController(ControllerContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeNextResourceFilter>d__22.MoveNext()
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeAsync>d__20.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Builder.RouterMiddleware+<Invoke>d__4.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+<Invoke>d__18.MoveNext()
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+<Invoke>d__18.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+<Invoke>d__18.MoveNext()
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+<Invoke>d__18.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+<Invoke>d__18.MoveNext()
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+<Invoke>d__18.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.VisualStudio.Web.BrowserLink.BrowserLinkMiddleware+<ExecuteWithFilter>d__7.MoveNext()
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+<Invoke>d__7.MoveNext()

SimpleInjector error > IToastNotification that is not registered

System.InvalidOperationException: 'The configuration is invalid. Creating the instance for type ProfileController failed. The constructor of type ProfileController contains the parameter with name 'toastNotification' and type IToastNotification that is not registered. Please ensure IToastNotification is registered, or change the constructor of ProfileController.'

container.Register<IToastNotificatio,ToastNotification>();
or
container.CrossWire<IToastNotification>(app);
Does not help.

How use NToastNotify with Simple Injector?

Error 400 with NToastNotify.ts line 139 if not call, Error 500 if call

I have implement successfully NToastNotify in my project (.Net Core 2.0.6 MVC). The messages are shown as expected on my Views. However, it got error 400 in case of using partial view, called via Ajax (POST and GET), if I comment my code calling NToast messages. I got error 500 if I used code calling NToast message.
My action is below, example for POST:
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult AddNewDep([FromForm]DepViewModel model)
{
SetViewDataStatic();
if (ModelState.IsValid)
{
var isExist = DepManager.Exist(model.DepName);
if (isExist == true)
{
toastMessage.AddErrorToastMessage($"Dep's name is used. Choose another name");
return PartialView(model);
}
var newDep = new Dep
{
//.....
};
var result = DepManager.InsertNewDep(newDep);
if (result > 0)
{
SetViewDataDynamic();
toastMessage.AddSuccessToastMessage("Successfully done");
return PartialView(model);
}
else
{
toastMessage.AddErrorToastMessage("Got error! Please try again later!");
return PartialView(model);
}
}
return PartialView(model);
}

Request header field X-NToastNotify-Request-Type is not allowed by Access-Control-Allow-Headers in preflight response.

Hello,

I'm facing an issue with NToastNotify. I'm trying to send a CORS ajax request, to get some data from the elasticsearch server on my local machine, and I discovered that the toastr.js intercepts somehow my requests. I'm pretty sure that this is the cause, because everything works fine when I do not include the client package in the _Layout.cshtml:

await Component.InvokeAsync("NToastNotify")

Here is the error I'm getting:

image

The JS code I'm running is the following:

window.esClient = $.es.Client({
    hosts: "http://127.0.0.1:9200/"
});

window.esClient.ping({
    requestTimeout: 30000,
}, function (error) {
    if (error) {
        console.error('elasticsearch cluster is down!');
    } else {
        console.log('All is well');
    }
});

I'm using jquery and the elasticsearch.js bower packages.
The local elasticserach server is configured to work with CORS request, so on that side everything is fine:

http.cors.enabled : true
http.cors.allow-origin : "*"
http.cors.allow-methods : OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers : X-Requested-With,X-Auth-Token,Content-Type, Content-Length

Application Insight CORS

When you use Application Insight it throws a cors error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://dc.services.visualstudio.com/v2/track. (Reason: missing token ‘x-ntoastnotify-request-type’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel)

Web Config:

 <httpProtocol>
      <customHeaders>
        <remove name="X-Powered-By" />

        <add name="Access-Control-Allow-Origin" value="*"/>
        <add name="Access-Control-Allow-Methods" value="GET,PUT,POST,DELETE,OPTIONS"/>
        <add name="Access-Control-Allow-Headers" value="Content-Type,x-ntoastnotify-request-type"/>
      </customHeaders>
    </httpProtocol>

Ajax request

How could i show the message if the partial view is loaded by ajax post ?
A bootsrap modal window is loaded via ajax request and i want to show a error message after the successful response. Do i need to add the component seperately on the partial view

Issue with documentation

Hi,

Thank you for taking the time to release this!

I came accross an issue that isn't really any fault of NToastNotify or yours, it's more of a VS2017 issue.

When using NuGet in Visual Studio 2017 to install something like this, or a css framework, nuget doesn't add the css or js files to the project, meaning we have to manually download them and add them to our project.

I'm not sure if its a bug or by design, however it does mean that your documentation is missing the instruction for users who don't realise that this issue exists.

I'm not sure it's something you should worry about, but thought I'd mention it. :)

Feature-request

Hi there, nice little library you've got there!

It would be nice if it would be possible to change the default options for the toastr notification (by calling the service), so we don't have to do it every time we call the "AddToastMessage".

Thanks for your work!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.