asp.net mvc 3 - Possible breaking change in MVC4 Razor that can be fixed with "@:@" -


I recently upgraded my website to ASP.Net MVC3 (Razor) to MVC 4 (Razor 2) , And doing so seemed like what it seemed like a breaker change in a razor-view engine.

The scenario (very simplified) is shown below.

  @Electrical IEnumerable & lt; String & gt; @ {Layout = null; } & Lt ;! DOCTYPE html & gt; & Lt; Html & gt; & Lt; Body & gt; & Lt; Div & gt; @foreach (X in Model) {@ string.format ("Foo Bar: {0}", x) // MVC4 / Razor2} errors & lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;   

This works fine in MVC3 / Razor, however results in an error in the string.Format line in MVC4 / Razor2:

Unexpected "string" keyword after the "@" character. Once inside the code, you do not need a prefix with "@" like "string".

If you delete @ , the visual engine then asks that you end the line with the semicolon string.format Give. However, Rishers then warns (correctly):

The return value of the net method is not used.

I made two fixes for this I & lt; Text & gt; :

  & lt; Text & gt; @ String.Format ("value {0}", x) & lt; / Text & gt; to use.   

or @: @ :

  @: @ string.format ("value {0}", X) < / Code>  

Is this a known and documented change in the RazorView engine?

It looks like a bug, it's string : @foreach (var x in model) {@ String.Format ("Foo bar: {0}", x)}

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -