kidoman
kidoman

Reputation: 2422

How to get a common element (like Version number) into Site.Master?

Suppose I have a Site.Master page.

I want to display something like the version number of the application (lets assume it is available in the the BaseController as a string) in the Site.Master.

What would be the best way to do that? I know one way would be to have a Base view model class which would contain the version element. But any better way?

Hope the question is valid.

Thnx,

Karan

Upvotes: 0

Views: 239

Answers (2)

Tom Carver
Tom Carver

Reputation: 1018

For something like an assembly version number it might be Ok to have it as a static property on the BaseController, in which case you could reference it directly from any code that needed it.


<%@ Import Namespace="ControllerNamespace"%>

<%=BaseController.MyProperty %>

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1039110

I would write a helper method for this:

public static class HtmlExtensions
{
    public static MvcHtmlString Version(this HtmlHelper htmlHelper)
    {
        string version = FetchVersionFromSomewhere();
        return MvcHtmlString.Create(version);
    }
}

And then in your master:

<%: Html.Version() %>

Upvotes: 2

Related Questions