Reputation: 673
I don't know if what i want to do is possible, but I have a JavaScript library i would like to use in the Server end of my Blazor app. Specifically in a service class.
My Blazor app has 2 environments, a Client and a Server. I am able to call my JavaScript functions on the client end using wwwroot/index.html and a blazor component, but i'm not sure how to go about doing it in the Server end. A lot of the documentation suggest providing the JavaScript function in Pages/_Host.cshtml but my project doesn't have (it has only Pages/_Layout.cshtml)
Any help is appreciated!
Upvotes: 0
Views: 225
Reputation: 17424
If you have a wwwroot/index.html and you don't have Pages/_Host.cshtml means you are using Blazor WASM project hosted by a Server project but the app code doesn't run on the server. It runs only on the browser.
If you want to use a JS library on the Server project you need to use nodejs and INodeServices
. You can read this post to know how to use it : https://www.c-sharpcorner.com/article/nodeservices-where-javascript-and-net-meet-back-on-the-other-side/
INodeServices
is now obsolete and there isn't replacement but you can still use it. Or you can choose to use Javascript.NodeJS instead.
Upvotes: 1