Reputation: 5223
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?
Upvotes: 2
Views: 1080
Reputation: 34810
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.
Upvotes: 1