Can I add pre-existing Javascript code to an ASP.NET MVC C# application

Apologies if this is a silly question. I currently have a small backend system written in ASP.NET Mvc in C# that allows you to do multiple features relating to profiles (Add, Edit, Delete, View) amongst other features.

My friend has an application he created as his University project and we’re both just curious if we can merge his application with mine as his is purely a front-end system and mine is a back-end.

He has written an SQL web application that tests you with some general T-SQL questions with a pre-set SQLite3 database that you can modify based on the questions asked. He has written it all in Javascript and using HTML and CSS. He has 3 folders, a folder contaning all the javascript, a folder with an SQLITE3 database and a folder with the HTML/CSS.

I was just wondering, can I essentially ‘drag and drop’ all the 3 folders into my application on Visual Studio and will it just run seamlessly?. I assume I will need to go into the Javascript and modify any changes to the paths of the database which I can do. I’m not interested in calling any js functions or anything yet, just making it so I can start the application, be taken the HTML for the SQL application and then all the js scripts work for that page.

If this is not the case, is it a case where I can only use Javascript by injecting it into ASP.NET by using the tag <script type="text/javascript">?

Trying what I have stated. As it webpage was in HTML, I created an action in my controller that opens up the HTML page in CSHTML. This will display the HTML but no methods are called when the page loads therefore no database is loaded or what I presume to be any Javascript commands.

If there are any materials that help with this issue, can you please link them below. I had done some research but could not find anything that points to this specific issue.

72 thoughts on “Can I add pre-existing Javascript code to an ASP.NET MVC C# application”

  1. Can I add pre-existing Javascript code to an ASP.NET MVC C# application


    Apologies if this is a silly question.

    It isn’t a silly question because there is an ambiguity in the question that might make the answer "no" in your specific case.

    Firstly the good news – you can reference scripts written in Javascript in your HTML, and you can put blocks of Javascript in you CSHTML too. It’s possible to use Razor to create a page that includes HTML, Javascript and C# in the same page – BUT there is a difference about where and when the code executes that might be an issue for you.

    The question you need to determine is if your friend’s project is written using the Node.js framework. Javascript is a language and it can be used in both front-end (execute in the client’s browser) and back-end applications.

    You can use your ASP application (which is server-side or back-end code) to write documents that either include Javscript or reference scripts to be executed by the client-side code in the browser. You can’t get your back-end to run the Javascript in the same application) as it is intended for a different framework.

    You can have two applications hosted on the same server, and make calls between them both and use them together in that respect, but otherwise you need to select one or other as the back-end providing framework for your web application.

    So you can include Javascript in your ASP application, but for execution on the client-side in their browser. Your mentioning of database connections heavily implies that you are describing server-side code – so talk to your friend about Node.js to ensure that is what they are using.

    You can read about Node.js here:

    There are some details about mixing ASP and Node on Azure here: Mixing node.js and ASP.NET projects in a single Azure Web Role?


Leave a Comment