✅ Calling toast library function in scaffolded cshtml.cs

Hi, Can someome please point on to how to use shared/mycomponent function in a scaffolded cshtml -> cs for example in identity/pages/account/manage/register.cshtml.cs i want to invoke my toast component https://github.com/Blazored/Toast
@inject IToastService toastService

@code {
public void Toast(string text)
{
RenderFragment message =@<text>@text</text>;
toastService.ShowToast(ToastLevel.Info, message);
Console.WriteLine("Not right!");
}
}
@inject IToastService toastService

@code {
public void Toast(string text)
{
RenderFragment message =@<text>@text</text>;
toastService.ShowToast(ToastLevel.Info, message);
Console.WriteLine("Not right!");
}
}
GitHub
GitHub - Blazored/Toast: A JavaScript free toast library for Blazor...
A JavaScript free toast library for Blazor and Razor Component applications - GitHub - Blazored/Toast: A JavaScript free toast library for Blazor and Razor Component applications
30 Replies
Mayor McCheese
Mayor McCheese13mo ago
Are you building a blazor app?
VitalJeevanjot
VitalJeevanjot13mo ago
Yes Mayor Blazor-server one I am js developer trying my hands on blazor
Mayor McCheese
Mayor McCheese13mo ago
So.... did you read the docs on it? The author does a better job explaining than anyone else will and has samples.
VitalJeevanjot
VitalJeevanjot13mo ago
Yes, i do. It works on components easily. But not when called from cshtml.cs file When i call the function from identity scaffolded register file, I get Object reference is not set an instance.... Then i try to use the component in cshtml file hoping this will initiaze the service but it doesn't refer it's like the builder references used with identity scaffolded or any scaffolded files is managed somewhere differently i am not getting the gist of it.
VitalJeevanjot
VitalJeevanjot13mo ago
VitalJeevanjot
VitalJeevanjot13mo ago
From where i need to call. Or to where i need to show the toast on some codition before adding user in db But since the serivce when i try to intialize there directly gives same error i tried to create this under a razor component The function you see there above
VitalJeevanjot
VitalJeevanjot13mo ago
VitalJeevanjot
VitalJeevanjot13mo ago
now using that inside another component will work as author mentioned but not when called in/from cshtml.cs file from identity
Mayor McCheese
Mayor McCheese13mo ago
I'm not certain of your solution right now, I feel like the first image you're showing is a regular mvc app, it's won't work there.
VitalJeevanjot
VitalJeevanjot13mo ago
it is same solution. same project ooooooo i missed it
Mayor McCheese
Mayor McCheese13mo ago
I built my own toast service in wasm a while before this one came out in the initial preview, we eventually swapped out my solution for this one and had no issues
VitalJeevanjot
VitalJeevanjot13mo ago
just saw in my own screen shot 😄 sounds good i will try out with something i just saw
Mayor McCheese
Mayor McCheese13mo ago
Saw what?
VitalJeevanjot
VitalJeevanjot13mo ago
VitalJeevanjot
VitalJeevanjot13mo ago
there is separate imports for this.... i thought all was done my main _imports but this was a view
Mayor McCheese
Mayor McCheese13mo ago
Hmmm I've not got a lot experience in blazor any longer it seems, mostly from the initial preview, I'm probably too out of touch with it
VitalJeevanjot
VitalJeevanjot13mo ago
its fine, i myself starting it out just now thank you Mr. Mayor
VitalJeevanjot
VitalJeevanjot13mo ago
@.mayormccheese Still not working In Register.cshtml.cs
VitalJeevanjot
VitalJeevanjot13mo ago
There is no error by toast doesn't appear is that possible that css is having some sort of conflic ?
VitalJeevanjot
VitalJeevanjot13mo ago
the component is declared in Register.cshtml
Mayor McCheese
Mayor McCheese13mo ago
If you check in the page is it rendering the html?
VitalJeevanjot
VitalJeevanjot13mo ago
it doesn't. I checked on components it renders but through cshtml it doesn't OnPostAsync the page reloads itself when i return null so maybe that's why it re renders the dom but i was expecting even a glimpse There is one more thing cshtml.cs renders on backend and cshtml works as front-end but i didn't found a way to tringger @function{void toastmaker(){}} from cshtml.cs file in cshtml file to see if it works from front-end file
VitalJeevanjot
VitalJeevanjot13mo ago
VitalJeevanjot
VitalJeevanjot13mo ago
It shows fired by razor components as prerendered state should work live on server but the thing with cshtml and cshtml.cs is a whole different process i think The code should have written in front-end but they wrote it in backend file. I do not know how to trigger front-end changes through backend file as ajax process
Mayor McCheese
Mayor McCheese13mo ago
They are different processes, so you're going to have trouble and essentially maintain two components ( I think ) I don't know much about blazor auth; when I had to do auth I had to hand-roll oauth for blazor since the components didn't exist yet.
Mayor McCheese
Mayor McCheese13mo ago
GitHub
blazor-workshop/save-points/06-authentication-and-authorization/Bla...
Blazor workshop. Contribute to dotnet-presentations/blazor-workshop development by creating an account on GitHub.
Mayor McCheese
Mayor McCheese13mo ago
it's not the database stuff you have, but should be somewhat plug and play this is also wasm, which is somewhat identical
VitalJeevanjot
VitalJeevanjot13mo ago
Thanks @.mayormccheese I have completed this workshop some weeks ago to get basics of it. Specially because it was from steve-sanderson so i belived it will be more clear and informative so i went through it and was good indeed. But thank you for you time. I will keep on trying.... Otherwise i will switch back to my own stack or probably go with mimal api don't know what to decide now
Mayor McCheese
Mayor McCheese13mo ago
Others may have more info, I answered because I dealt with this particular component a lot, but not in your cirucmstances unfortunately.
VitalJeevanjot
VitalJeevanjot13mo ago
Still thanks
Want results from more Discord servers?
Add your server
More Posts
How to I write an equation to raise a variable to another variable using a for loop?I can't use Math.Pow() here, it has to be a loop. If there's an easier loop to use here, I would def❔ My asp.net endpoint throws a error when it receives stringMy endpoint takes a integer and 2 strings from the frontend. The frontend is sending a integer and 2❔ Anyone knows any qr code reader that uploads the qr image then output it as a json/stringTill beginner with c#✅ Authorize() Attribute is not working (SOLVED)Hello everyone, I implemented Jwt in .net 6 for a project. I have shared my JwtHelper and program cl✅ Implementing IDisposable properlyI have a class I implemented IDisposable in which subscribes to an observable of a type. Example: su❔ Help with Assemblies and the TypeRef tableI am trying to load a .NET DLL as an assembly and read the TypeRef table. End goal is to get all the❔ Python Decorators in C# ??? How do i intercept method calls with attributes?Is is possible to intercept/prevent a method call in c# with attributes? i was thinking about someth❔ AspNetCore web MVC app - AuthenticationI would like to implement some authentication to my web app. I would like to make it "proper" and no❔ .net 7 docker container error: qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2' HELPI am getting this error (qemu-x86_64: Could not open '/lib64/ld-linux-x86-64.so.2': No such file or ✅ Cant open .csporjSo i made a WFA and i want to edit the .csproj file but i cant open it