Javascript with ASP.NET MVC

TkTech 56 Reputation points
2021-04-16T07:08:46.42+00:00

Hi,
As ASP.Net Webforms is mostly obsolete, I want to brush my JavaScript and MVC skills . But most tutorials point to JavaScript with ASP .NET Web forms.

My question, Is JavaScript not used with ASP.NET MVC?

Am in the right direction of technology selection ? Please guide me.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,400 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,280 questions
{count} votes

Accepted answer
  1. Chao Deng-MSFT 796 Reputation points
    2021-04-19T08:26:48.547+00:00

    Hi @tanimakumari-5311,
    JavaScript can be used in asp.net mvc.
    If you go for Asp.NET Web forms, there is no need to have a detailed understanding of HTML, CSS or JavaScript as it abstracts all these details and provides automatic plumbing. However, if you’re using ASP.NET MVC, you will need a clear understanding of how HTML, CSS and JavaScript work.
    Below is an example using Razor syntax combined with a simple demo of javaScript.
    First create a Controller, and then add a view, the code of the View part is as follows:
    W9tql.png
    Result:
    When you click "Click to show time!", the current time will be displayed below.
    8OvPG.png
    For more usage syntax, please refer to the example.
    Introduction to ASP.NET Web Programming Using the Razor Syntax (C#)
    You can also use some js frameworks, such as angular ,Vue , ember.


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,

    ChaoDeng

    1 person found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Ken Tucker 5,846 Reputation points
    2021-04-18T10:48:51.96+00:00

    Yes you use javascript with asp.net MVC. here is one article showing MVC with Angular a javascript library

    1 person found this answer helpful.

  2. Duane Arnold 3,216 Reputation points
    2021-04-19T15:19:31.053+00:00

    You can use JavaScript with ASP.NET MVC views just like it can be done with ASP.NET Webforms. There is nothing different about the DOM or HTLM controls on a MVC view as opposed to Webform in using JavaScript.

    http://www.codedigest.com/posts/35/adding-javascript-in-aspnet-mvc-views

    You should look into using a Razor page project that is similar to using Webforms and the codebehind file that is still using the MVC pipeline.

    1 person found this answer helpful.

  3. Lo67 11 Reputation points
    2021-04-19T23:33:10.237+00:00

    In addition to previous answers, I suggest you trying to create a new "ASP.NET Core Web Application (Model-View-Controler)" project.

    Visual Studio will create default files and folders...
    In the "/wwwroot/lib" folder, you will found a "jquery" folder as JQuery is used for some validations for example.
    There is a "/wwwroot/js/site.js" file ready to be completed by your own. In this one, line 4 says "// Write your JavaScript code." ;-)

    ASP.NET MVC even have integrated functions to bundle and minize your different Javascript files.

    1 person found this answer helpful.