Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, everyone!

In my MVC 5 project, I have a Resource File for Internationalization purposes, and it includes validation. In this case, I created a custom validation attribute for my RegisterViewModel so that I could validate a Birthdate Range based on minimum age and maximum age. Therefore, I need the validation error message to be multilanguage, hence the need to add an entry to my .resx file.

The problem is that in the case of the message needing computed information like:

"The birthdate must be between @DateTime.Today.AddYears(-100) and @DateTime.Today.AddYears(-18)"

...that Razor syntax will not be recognized as Razor syntax. This message has to be translated into 3 more languages, so computing those dates inside the validation message is a must.

So, how can I include Razor Syntax inside the value of the Resource Key?

Thanks in advance!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900