Razor 2 (which ships with MVC4) doesn’t seem to be fully backwards compatible with Razor 1 (from MVC3).
Since upgrading, I found an error:
The “td@Html.Raw(count” element was not closed. All elements must be either self-closing or have a matching end tag.
The code that caused this was:
<td@Html.Raw(count == null ? null : " class='has-item'")>
What is the solution to this?
The Razor parser was re-written for MVC 4, presumably because:
The simplest solution here is to add a single space before the
@symbol:However, conditional attributes in Razor with MVC 4 have a more elegant syntax.
When an attribute value resolves to
null, the attribute is omitted from the element. So the output of this markup is either:…or…