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

Sweet Alert 2 js library with Interop from blazor server

$
0
0

I have a blazor server app in which I want to use sweetalert2 methods, I want to do it using js interop , not by nuget sweetalert package. Below is my code

App.razor

<body><Routes @rendermode=RenderMode.InteractiveServer /><script src="bootstrap/jquery.min.js"></script><script src="bootstrap/bootstrap.bundle.min.js"></script><script src="sweetalert2/sweetalert2.all.min.js"></script><script src="js/app.js"></script><script src="_framework/blazor.web.js"></script></body>

included sweetalert2.all.min.js before _framework/blazor.web.js

And in c# code on a function click

 private void CallJs(){    Js.InvokeVoidAsync("Swal.fire", args: "Some message to display");}

This should invoke simplest sweet alert form as below

Swal.fire("SweetAlert2 is working!");

But above is not working

I tried with another file with normal alert as

   function sayHello(name) {    alert(`Hello ${name}`);}

and in c#

 private void CallJs() {     Js.InvokeVoidAsync("sayHello", args: "Bob"); }

and above works , but when use js interop with a library like sweetalert, bootstrap .... it does not work, how to call properly sweetlaert methods here ?

I am using .net 8.0


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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