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 assu开发者_JS百科me 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
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() %>
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 %>
精彩评论