How to add custom script files to your project.
Adding a custom script is not much complicated in ASP.NET MVC but still we have to follow some steps to accomplish this task.
First add a folder called “custom” or whatever the name you want and add a .js file inside that folder.
Now we have to register that custom folder and the custom script file. So we need to go to the “BundleConfig.cs” file inside the “App_Start” folder.
After that we have to tell the Razor engine to render this custom bundle into all the pages, so we have to add this to the “Layout” view or any other master views.
Go to Views -> Shared -> _Layout.cshtml file and add the render code.
Ok. We are done with the registration. Now we have to check whether its working or not. So add a button on home page.
Go to Views -> Home ->Index.cshtml and add a button
<input type=”button” value=”Click me” id=”hellobtn” class=”btn btn-danger”/>
now we can catch the button click event and show an alert message.
in our custom js file add the button click event.
When you click on the newly added button, you can see the alert message.