views:

30

answers:

2

Hi guys,

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

+3  A: 

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() %>
Darin Dimitrov
very nice @ Darin. how i can write this in my MVC web-application
4thpage
And that's exactly what I had done... thanks for confirming :)
KiD0M4N
+1  A: 

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 %>
Tom Carver
While this method is also feasible, it won't apply in my particular case.
KiD0M4N