How to embed a YouTube Video in MVC5 in ASP.NET

Here is one simple way of embedding the Youtube Video in your MVC5 Page in Visual Studio.

Infact this method will work on any HTML Page.

 

1. First you need a YouTube Video. Go to YouTube and find a Video which you want to display. Copy the URL which is displayed in the browser address bar.

You would have a URL like the following one

https://www.youtube.com/watch?v=dwqDGLQIINY

 

 

2.You can simply embed this video on your page using the following script

           <iframe width=”560″
height=”315″
src=”http://www.youtube.com/embed/dwqDGLQIINY
frameborder=”0″
allowfullscreen>

</iframe>

 

 

3. If you would also like to display the default image of the YouTube Video then you can use the following script.

 

<img src=”http://i3.ytimg.com/vi/dwqDGLQIINY/mqdefault.jpg”/>

If you are displaying a number of videos or a video gallery then simply replace the Video IDs (shown in red) for each of the video.

 

 

There are so many other ways to embed the YouTube videos, but I find this is the easiest and suitable for my needs.