ASP.NET MVC Hosting :: Play or Display Video in ASP.NET MVC Using HTML5

It is very easy to play or display video in ASP.NET MVC using HTML5. We can do this using custom action filter in MVC. We can play various files like MP4, Ogg, WebM, etc. format.

ahp banner aspnet mvc-01Here are step by step tutorial to play video in ASP.NET MVC using HTML5.
Here is example for this.

In this example we are taking .MP4 file to play in browser.

STEP : 1
Create an ASP.NET MVC Empty application in visual studio. Give project name like ‘PlayVideoInMVC’.

STEP : 2
After creating empty application create new folder ‘VideoDataFile’ after that add video files in this folder.

STEP : 3
Now we are going to add custom action filter. Add new folder ‘CustomDataResult’ and add new class file ‘VideoDataResult.cs’. In this class we need to inherit ‘ActionResult’ class and override ‘ExecuteResult’ method.

In method we write code like read video file and send response back to controller using “context.HttpContext.Response.BinaryWrite” method.

Below is code for ‘VideoDataResult.cs’ file :

STEP 4 :
Now we are going to add our controller that can take care of Video data result. Now add one MVC controller and name it ‘VideoDataController’ in ‘Controller’ folder.

Below is code for ‘VideoDataController’ file :

STEP : 5
Now add new controller to view or display video name it ‘ViewVideoController’, after that add ‘view’ and in this ‘view’ add HTML5 video tag to play video in video player.

In this view we also add one download video link. This link allows to download video. On clicking of this link you will see the download file dialog box.

Below is the HTML markup of ‘View’ :

We need to set ‘src’ property of video tag to get video data and play that. Now run the application with this URL ‘http://localhost:[your port]/ViewVideo’. I ran this in chrome. You can run on any other HTML5 enabled browser.

Here is a very useful link to check that does your browser support HTML5 video and also which video format support.

Important : One important thing to note here is that we can use our custom action filter for two purposes, first to display video on browser and Second allow to download video file.

So the same controller serves two purposes. We can centralize our code by doing this.


1sdkjvBest ASP.NET MVC Hosting Recommendation’s Best ASP.NET hosting platform on Windows 2012 and Windows 2008 is compatible with ASP.NET MVC hosting. Needless to say, you’ll be able to really feel very comfy with their hosting service. Their best and inexpensive ASP.NET MVC hosting package is starting from $1.00/mo only. And with their promo code, you will get free domain as well. Not just that, in addition they supply 30 days cash back guarantee. Their servers are 99.99% uptime, it’s important believe which you require for your ASP.NET MVC site, so your website is by no means down. offer the Best, Cheap and Recommended ASP.NET MVC hosting start from €1.29/month. They can load your site against anticipated traffic and recommend the best option for you. is Microsoft No #1 Recommended Windows and ASP.NET Hosting in European Continent. Their service is ranked the highest top #1 spot in several European countries, such as: Germany, Italy, Netherlands, France, Belgium, United Kingdom, Sweden, Finland, Switzerland and many top European countries.
Get high functionality, best uptime along with the most dependable ASP.NET MVC Hosting site with them. ASP.NET MVC hosting from provides a protected, trustworthy and performance-driven foundation for your website and apps. If you’re searching for the correct Windows ASP.NET hosting that support ASP.NET MVC hosting provider, they are the correct selection for you. They have proactive monitoring down to seconds with reactive options in spot to ensure the stability in the services they offer. All hosting servers are monitored 24/7/365. They use enterprise software to monitor their whole network infrastructure. Their very best and inexpensive ASP.NET MVC hosting price begins from $2.00 monthly.

Leave a Reply

Your email address will not be published.