question

TkTech avatar image
0 Votes"
TkTech asked TkTech edited

Javascript with ASP.NET MVC

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.

dotnet-aspnet-mvcdotnet-standard
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I would suggest you to not go with asp.net mvc, instead go for ASP.NET Core MVC.

1 Vote 1 ·

Thanks, @YogiS-3643 for replying.
But before learning Core, should I not learn MVC , as I am from Webforms ASP.Net background ?
Also, is it necessary to learn JS frameworks like Angular etc. Just knowing Javascript with MVC or Core will not suffice?

0 Votes 0 ·

No need to learn ASP.NET MVC you can staraight way learn ASP.NET Core MVC. There is also no need to learn Angular as angular is itself quite big to learn, it will take many month (about 6 ) for you to become good in Angular. Just learn ASP.NET Core MVC and then JavaScript is very easy, it will take just 2 days for you to be become familiar with JavaScript. Remember we are just humans we cannot learn every thing. So just learn things that you can become good at over a period of time and get proper job in it.

1 Vote 1 ·
Show more comments
ChaoDeng-MSFT avatar image
1 Vote"
ChaoDeng-MSFT answered TkTech edited

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks, @ChaoDeng-MSFT for replying.
I have understanding of JS, CSS, HTML. Reading all your posts , which JS framework should I start learning, Angular or React or JQuery ?
Or is this even required?

0 Votes 0 ·
vb2ae avatar image
1 Vote"
vb2ae answered TkTech commented

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


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks, shall check it.

0 Votes 0 ·
DuaneArnold-0443 avatar image
1 Vote"
DuaneArnold-0443 answered TkTech commented

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks, @DuaneArnold-0443 for the suggestion.

0 Votes 0 ·
Lo67 avatar image
1 Vote"
Lo67 answered TkTech commented

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.

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks, @Lo67 for giving this insight.
But before learning Core, should I not learn MVC , as I am from Webforms(ASP.Net) background ?
Also, is it necessary to learn JS frameworks like Angular etc. Just knowing Javascript with MVC or Core will not suffice?

0 Votes 0 ·

Your welcome !

Oh, yes you're right : one step after the other ! Learning "MVC" in ".NET Framework" will be an easier step than getting directly to ".NET Core".

You can find a ".NET Framework" version of "MVC" too. I used it on a former job, in an application with client side validation and without writing any line of JavaScript code.
For others applications we used JavaScript to deal with "AJAX" calls (to "WebAPI" and/or "SignalR").
So, yes, just knowing "MVC" and "JavaScript" would sufice :-)

The latest tutorial on "MVC" are for ".NET Core" but there is a nice tutorial for ".NET Framework" here :
https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/introduction/getting-started

Working with "Angular" is much more a client side application working with a "WebAPI".

1 Vote 1 ·

Thanks, @Lo67 , shall go through.

0 Votes 0 ·

Thanks @DuaneArnold-0443 for listing out so many links. I shall go through them.

0 Votes 0 ·