ASP.NET MVC 3 中的当前年份

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6190760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 15:36:32  来源:igfitidea点击:

Current Year in ASP.NET MVC 3

.netasp.net-mvc-3razor

提问by Marta

I want to add Copyright @ 'current_year' to the footer (in cshtml file) of my page. I often made it using javascript but since I am using ASP.NET MVC 3 I would like to do this using ASP.

我想将 Copyright @ 'current_year' 添加到我页面的页脚(在 cshtml 文件中)。我经常使用 javascript 制作它,但由于我使用的是 ASP.NET MVC 3,我想使用 ASP 来做到这一点。

I was trying construction like:

我正在尝试构建,如:

@response.write("Current Year: "&Year(Date))

But it didn't work in MVC 3 and I can't find solution that is working.

但它在 MVC 3 中不起作用,我找不到有效的解决方案。

回答by Darin Dimitrov

Try the following:

请尝试以下操作:

Copyright @@ @DateTime.Now.Year

回答by sophievda

In a .razor page in an ASP.NET Core application, e.g. within the <div> </div>of your footer, the following works too:

在 ASP.NET Core 应用程序中的 .razor 页面中,例如在<div> </div>您的页脚中,以下内容也适用:

Copyright &#169 @DateTime.Now.Year

Added the copyright sign too and the double @@ is not needed in a razor page; it gives an error.

也添加了版权标志,剃刀页面中不需要双@@;它给出了一个错误。