0

I want to show the version info of the current project on every page.

The way I do it in the moment is like this:

Inside the Index method of my homecontroller:

ViewBag.Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

Inside the _layout.cshtml(masterpage):

@ViewBag.Version

The Problem here is, it will only displayed once, but I want to display the Version on every page/view.

This is my routing configuration:

        public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }


        );
    }

Do I have to change something here ?

Ty for helping

user254197
  • 883
  • 2
  • 9
  • 31

2 Answers2

1

Why not just call

@System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

on the _Layout.cshtml view?

MVC has a different launch context and a work around is needed to text the version:

@typeof(HomeController).Assembly.GetName().Version

HomeController could be replaced with any other type in the assembly the MVC application assembly. See this question for more info.

Community
  • 1
  • 1
Henk Mollema
  • 44,194
  • 12
  • 93
  • 104
0

Just put this in the Layout.

<label>@System.Reflection.Assembly.GetExecutingAssembly().GetName().Version</label>
Ishtiaq
  • 980
  • 2
  • 6
  • 21