✅ 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
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
Are you building a blazor app?
Yes Mayor
Blazor-server one
I am js developer trying my hands on blazor
So.... did you read the docs on it? The author does a better job explaining than anyone else will and has samples.
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.
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
now using that inside another component will work
as author mentioned
but not when called in/from cshtml.cs file from identity
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.
it is same solution.
same project
ooooooo
i missed it
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
just saw in my own screen shot 😄
sounds good
i will try out with something i just saw
Saw what?
there is separate imports for this....
i thought all was done my main
_imports
but this was a viewHmmm 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
its fine, i myself starting it out just now
thank you Mr. Mayor
@.mayormccheese
Still not working
In
Register.cshtml.cs
There is no error by toast doesn't appear
is that possible that css is having some sort of conflic ?
the component is declared in Register.cshtml
If you check in the page is it rendering the html?
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
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
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.
https://github.com/dotnet-presentations/blazor-workshop/tree/main/save-points/06-authentication-and-authorization/BlazingPizza.Server This is a blazor demo kinda maintained by the blazor team
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.
it's not the database stuff you have, but should be somewhat plug and play
this is also wasm, which is somewhat identical
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
Others may have more info, I answered because I dealt with this particular component a lot, but not in your cirucmstances unfortunately.
Still thanks