We are in the process of upgrading a .NET mvc app from MVC3 to MVC5, which includes an upgrade from Razor 1 to Razor 3. One error we keep hitting in views is the following:
In MVC3, many of our views do this:
@if (someCondition)
{
@* render some content *@
@string.Format(...)
}
However, in MVC5 this gives the following error:
System.Web.HttpParseException: Unexpected "string" keyword after "@" character. Once inside code, you do not need to prefix constructs like "string" with "@".
There are two easy fixes that I know of:
@if (someCondition)
{
@* render some content *@
@: @string.Format(...)
}
Or
@if (someCondition)
{
@* render some content *@
<text> @string.Format(...) </text>
}
However, it will be painful to make and test these changes across hundreds of views. Thus my question is: what is the best way to address this seemingly breaking change?
- Is there some kind of flag we can turn on to make razor behave as it used to?
- What is the recommended style for this kind of construct in Razor 3?