Check Your ASP.NET MVC Version Installed In Your System Using Code During Runtime

Create an Application named MVC version

Look at an example for better reference i.e. RouteConfig.cs


Create A Controller named “Home” .

Add the code given below in HomeController.cs for better results, as expected. 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.Mvc;  
  6. namespace Mvc_Version.Controllers {  
  7.     public class HomeController: Controller {  
  8.         //  
  9.         // GET: /Home/  
  10.         public string Version() {  
  11.             return "<h2>The Installed Mvc Version In your System Is : " + typeof(Controller).Assembly.GetName().Version.ToString() + "</h2>";  
  12.         }  
  13.     }  
  14. }   

 
We mentioned the controller action method version In HomeController.Cs

For this, we should change the action method name in RouteConfig.cs for better loading of the page. For the first time, we will make it a start page.

Add the highlighted code in your file of RouteConfig.Cs. 

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.Mvc;  
  6. using System.Web.Routing;  
  7. namespace Mvc_Version {  
  8.     public class RouteConfig {  
  9.         public static void RegisterRoutes(RouteCollection routes) {  
  10.             routes.IgnoreRoute("{resource}.axd/{*pathInfo}");  
  11.             routes.MapRoute(name: "Default", url: "{controller}/{action}/{id}", defaults: new {  
  12.                 controller = "Home", action = "Version", id = UrlParameter.Optional  
  13.             });  
  14.         }  
  15.     }  
  16. }   



Output

The expected output is shown below.


http://localhost:49952/Home/Version

Home - Controller name

Version - Controller action method

Next Recommended Reading Install Bootstrap In ASP.NET MVC 5