Razor + Visual Studio bug: don’t paste whitespace in code

Just a quick note of a bug my wife discovered when working with some Razor code.

If you have ASP.NET MVC 3 Release Candidate installed, you can trigger this. Take a spot where your view file has a C# expression (such as @View.Title), and paste some code after that expression. An example of the code might be “.Trim(' ')”.

Pasting that would have you expect a result of @View.Title.Trim(' '), but instead you end up with @View.Title '').Trim('.

The problem is that pasting a C# segment with whitespace in it causes Visual Studio to mutilate the code strangely. This is particularly apparent when pasting heavy method calls with spaces between arguments. Well, yet another reason to avoid code in your Razor files!

The Razor team confirmed via email that this is a bug in the Release Candidate and will be fixed in RTM.

November 30, 2010 В· Jouni Heikniemi В· No Comments
Tags:  В· Posted in: .NET, Web

Leave a Reply