Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Toast Component not working in Razor app C#

$
0
0

New to Blazor, kind of surprised there is no built in Dialog or Toast. Blazored-Toast to the rescue! Unfortunately, I can't get it to work. I suspect I am missing some critical step or some inclusion of some library, but I cannot identify it.

First what I have already looked at:

https://stackoverflow.com/questions/69091643/blazored-toast-not-working-from-the-view-model#:~:text=1.%20I'm%20trying%20to%20get%20some%20toast%20to%20appear%20in

Also

https://github.com/Blazored/Toast/tree/main

Where I went thru the samples and the ReadMe.

I believe I have implemented everything but obviously not.

So here is the code:

MainLayout.Razor

@inherits LayoutComponentBase@using Blazored.Toast;@using Blazored.Toast.Services;@using Blazored.Toast.Configuration<BlazoredToasts Position="ToastPosition.TopRight"                Timeout="10"                ShowCloseButton="@true"                MaxToastCount="3"></BlazoredToasts>

Program.cs

using Blazored.Toast;using MyStuff.Web;using MyStuff.Web.Components;var builder = WebApplication.CreateBuilder(args);// Add service defaults & Aspire components.builder.AddServiceDefaults();// Add services to the container.builder.Services.AddRazorComponents().AddInteractiveServerComponents();builder.Services.AddOutputCache();builder.Services.AddBlazoredToast();...

App.Razor

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><base href="/" /><link rel="stylesheet" href="bootstrap/bootstrap.min.css" /><link href="_content/Blazored.Toast/blazored-toast.min.css" rel="stylesheet" /><link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"          integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous"><link rel="stylesheet" href="app.css" /><link rel="stylesheet" href="MyStuff.Web.styles.css" /><link rel="icon" type="image/png" href="favicon.png" /><HeadOutlet /></head><body><Routes /><script src="_framework/blazor.web.js"></script></body></html>

MyStuff.Razor

@using System.Data;@using Blazored.Toast;@using Blazored.Toast.Services;@using Blazored.Toast.Configuration;@attribute [StreamRendering(true)]@attribute [OutputCache(Duration = 5)] <PageTitle>My STuff </PageTitle><h1>My Stuff</h1><p>Trying to get Blazored Toast to show up</p><EditForm Model="@batchModel"><button class="btn btn-success" @onclick="@(() => ToastService.ShowSuccess("I'm a message trying to show Toast"))">Success Toast</button>....

_Imports.razor

@using System.Net.Http@using System.Net.Http.Json@using Microsoft.AspNetCore.Components.Forms@using Microsoft.AspNetCore.Components.Routing@using Microsoft.AspNetCore.Components.Web@using static Microsoft.AspNetCore.Components.Web.RenderMode@using Microsoft.AspNetCore.Components.Web.Virtualization@using Microsoft.AspNetCore.OutputCaching@using Microsoft.JSInterop@using CollectXScore.Web@using CollectXScore.Web.Components@using Blazored.Toast@using Blazored.Toast.Services

What happens is nothing no errors, nothing displayed when I click the button. Interestingly if I put in a timeout I can see the delay of the timeout (meaning it is doing something) but for some reason it does not display the toast. Perhaps I need to show how reference Material?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>