Current Year in ASP.NET MVC 3

.Netasp.net Mvc-3Razor

.Net Problem Overview


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.

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.

.Net Solutions


Solution 1 - .Net

Try the following:

Copyright @@ @DateTime.Now.Year

Solution 2 - .Net

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

Copyright &#169 @DateTime.Now.Year

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMartaView Question on Stackoverflow
Solution 1 - .NetDarin DimitrovView Answer on Stackoverflow
Solution 2 - .NetsophievdaView Answer on Stackoverflow