2

I want to include in the layout view of my ASP.NET MVC application the version.

I use this in index action to get the version:

    var version = Assembly.GetAssembly(typeof(HomeController)).GetName().Version;
    ViewBag.Version = version + " / " + YlaGeneralUtilities.GetBuildDateTime(version);

Afterwards in the view i simply output Viewbag.Version.

I want the version to exist anywhere and not only to the homeController/Index action.

One workaround is to include the actual code above in the layout view:

@{
    var version = Assembly.GetAssembly(typeof(HomeController)).GetName().Version;
    ViewBag.Version = version + " / " + YlaGeneralUtilities.GetBuildDateTime(version);
}

But i dont like the idea of having "logic" in the view..Is this the only way?

e4rthdog
  • 5,103
  • 4
  • 40
  • 89

1 Answers1

1

Here's an alternative:

You could use a little "utility" controller in combination with jquery to populate the version value in your views asynchronously. The controller would have a single Action: GetVersion. This wouldn't take much code and should work cleanly across the site if you use an element in the layout.

Dave Swersky
  • 34,502
  • 9
  • 78
  • 118
  • nice idea, but one question: i put the element in layout and the script in section scripts. Thi will ensure that it will run at the end of page load? – e4rthdog Oct 08 '13 at 14:57
  • 1
    This looks like the information you need to ensure loading order: http://stackoverflow.com/questions/15347628/proper-place-to-load-jquery-in-mvc-layout-view – Dave Swersky Oct 08 '13 at 15:01