Dotnet logo

The .NET Tools Blog

Essential productivity kit for .NET developers


ReSharper 6 Enhances Razor Support

Previous posts introducing ReSharper 6:

Razor is the new View Engine introduced by Microsoft in ASP.NET MVC 3. If you have worked with ASPX View Engine, the default one up to version 2 of MVC, you’ll certainly appreciate the simplicity and ease of use of Razor. It makes the flow of HTML vs Code much easier to the eyes and to work with. In ReSharper 6, we are enhancing Razor support in Visual Studio by adding a series of features that will make it even better to work with.

Importing Namespaces

ReSharper 6 now automatically imports the specific namespace for your model:

Hitting Alt+Enter (QuickFix) will add the using statement


If you prefer to have a fully qualified name, that is:


you can change the setting under the Namespace Imports for C# under ReSharper Options (we are looking at the possibility of making this setting independent from general C# settings).

Creating from Usage

If a specific Model does not exist, ReSharper now allows you to create it from usage:


placing the Model automatically in the Models folder:


Helping with Sections

Razor has support for Sections. ReSharper enhances this support by providing Code Completion for Sections. The following shows a section defined in the _layout.cshtml file


We now get Code Completion for this section in any child page by typing @section


This provides us not only with Intellisense, but prevents us from making. If we were to type Footeer instead of Footer, ReSharper would highlight this error



Razor files are made up of code and HTML. As such, you also have Refactoring options that are applicable to both languages. For instance, the picture below depicts a refactoring of an HTML tag:


whereas the following is a Refactoring of some C# code


In fact, for ReSharper it doesn’t matter where your C# code starts and where your HTML ends. Just like Razor, ReSharper is capable of providing the correct contextual menus. The following is displayed when prompting the Refactor This menu (Shift+Ctrl+R) on the @text variable


ReSharper also knows how to handle situations where certain Razor constructs are required based on the outcome of a Refactoring option. Take the following code:


if we are to apply the Invert if refactoring, we would obtain:


where ReSharper conveniently places the @: which allows mixing of code and plain text.

Refactoring Helpers

Razor provides support for two types of Helpers, the classic Extension Methods that were available in the ASPX View Engine and Declarative Helpers, which are new to Razor. Declarative helpers are placed in the same file usually and avoid having to define an extension method or pre-post conversions. Given the following code:


we can invoke the Refactor This menu (by selecting the input tag line) and select Extract Helper:


ReSharper prompts us with the following dialog box:


resulting in the following refactoring


Currently Helpers are placed inline in the same Razor file, although we are looking at providing common helpers in App_Code folder as well as Extension Methods.

Navigation and Selection

Razor also now supports all the goodness of Navigation and other features of ReSharper such as Extend Selection (Ctrl+W). We can now navigate to and from Razor Views, go to Actions, Controllers:


as well as User Controls:


ReSharper Intellisense

We now get the full benefits of ReSharper Intellisense in Razor


with Razor-specific entries which allow for easy completion for constructs such as defining Models, Using or Flow statements. Similar to ASPX View Engine, we also get Intellisense for Actions, Controllers and User Controls:


and just like ASPX, we can also do Create From Usage:


On the Controller Side, ReSharper 6 now supports the built-in Scaffolding dialog for creating Views:


which allows us to have the QuickFix of Alt+Enter and take advantage of Visual Studio’s Scaffolding support.


Last but not least, ReSharper wouldn’t be ReSharper without its in-depth analysis of source code. And Razor support wouldn’t be complete without it either. In ReSharper 6 we provide full analysis of Razor files, providing you with insight on errors, hints, warnings along with their associated QuickFixes:


along with full right-margin analysis of the file:



As you can see, Razor support in ReSharper 6 is pretty extensive, although it’s not entirely complete yet. We are still in Early Access Program and would love to hear your feedback, whether they are bug reports or suggestions on how to even make it better. Please download the EAP and play with it and report any issues you find on YouTrack

[IMPORTANT: Please note that some code snippets shown are neither endorsed or recommended. They are merely for demonstration purposes. Code in Views should usually be restricted to View Logic and Rendering]

Comments below can no longer be edited.

9 Responses to ReSharper 6 Enhances Razor Support

  1. Anthony Shaw says:

    April 18, 2011

    Way to go Resharper! You guys rock!

  2. Markus Zywitza says:

    April 18, 2011

    That’s all fine, thanks.

    Unfortunately, JetBrains didn’t let me know so far when I can buy a license for R#6, or at least an upgradable R#5 license…

  3. Hadi Hariri says:

    April 18, 2011


    We will be releasing information about licensing soon. Thank you for your patience.

  4. Roland says:

    April 18, 2011

    Any discounts for long time users / eap contribs ?

  5. Daniel says:

    April 19, 2011

    im waiting to for the announcement of r#6 or upgradable before I make the plunge, hope not too much longer

  6. Chris says:

    May 5, 2011

    Can I assume that these Razor improvements will include all the regular refactoring operations?
    For instance, if I use my Resharper (v5) to rename a class property – that refactoring does not currently flow through into my cshtml files.

  7. Hadi Hariri says:

    May 5, 2011



  8. Max says:

    November 12, 2011

    One of the biggest improvements that i would like to see in this is for globalization – i think you already have static markup to resx string globalization for ASPX pages.
    Is the same feature on razor markup in your feature list??

  9. Jura Gorohovsky says:

    November 13, 2011

    Razor localization is coming in ReSharper 6.1 – we would appreciate if you try out the early access builds of this free upgrade and ensure that Razor i18n works well for you. If you have any issues with it, please let us know!

Discover more