Say I have a Class Library containing a HelloWorld.js file.
This file contains a couple javascript functions, like say:
function Hello_alert() {
alert("Hello World!!");
}
and
function Hello_console() {
console.log("Hello World!!");
}
I want to make so I can access the functions inside the HelloWorld.js file individually, on an ASP.NET MVC page, say, the Index.cshtml inside the Home folder. (Failing that, I'd be happy just accessing the .js file at all.)
I have already changed the .js as EmbeddedResource and added it to the Assembly as such:
[assembly: WebResource("JSLibrary.Scriptss.HelloWorld.js", "application/x-javascript")]
; referenced the DLL on my MVC project, and the DLL namespace shows up on Intellisense so I'm guessing it's linked right.
Now, I've been googling incessantly the whole day, and I've found a solution that kinda does what I need, but it's for Web Forms, using Page.ClientScript to register the scripts into the page itself, which allows one to call the functions inside the .js file on that page. This is pretty much what I'm trying to do, except I need it in MVC, which doesn't use the "Page" class like that.
The closes equivalent I've found has something to do with bundles, but I couldn't find any tutorials that I could viably follow.
So again, my question is, how do I somehow register Javascript files from a DLL in order for me to be able to call them from an ASP.NET MVC project?
--------Update:---------
Following the tutorial I linked above, my DLL has a class with a method that is used to register the scripts in a Script Manager, that it receives as a parameter. Like so
public static void includeHelloWorld(ClientScriptManager manager)
{
manager.RegisterClientScriptResource(typeof(JSLibrary.JSAccess), ScriptPath_HelloWorld);
}//JSLibrary being the DLL namespace and JSAccess being the class
Then, in the main project, using Web Forms, you can call that method and pass it the ClientScript property of the current Page, where the scripts get registered, I assume. Like so:
protected void Page_Load(object sender, EventArgs e)
{
JSLibrary.JSAccess.includeHelloWorld(Page.ClientScript);
}
I've tried it and it works on Web Forms. I need the equivalent of the Page.ClientScript in MVC, that I can send to the method in the DLL that takes in a ClientScriptManager.
Thanks