Print Version Number in ASP.NET MVC 4 app

前端 未结 7 2035
灰色年华
灰色年华 2020-12-23 19:15

I have an ASP.NET MVC 4 application. Currently, I am setting the version of the application in the project properties under the \"Application\" tab. From here, I click the \

7条回答
  •  被撕碎了的回忆
    2020-12-23 19:25

    I usually make HtmlHelper extension for this purpose. Something like this:

    public static class HtmlHelperExtensions
    {
        public static IHtmlString AssemblyVersion(this HtmlHelper helper)
        {
            var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            return MvcHtmlString.Create(version);
        }
    }
    

    And than inside view you just call:

    @Html.AssemblyVersion()
    

提交回复
热议问题