Posts Tagged ‘ASP.NET MVC’

ReSharper’s Web Path Mapping Explained

Monday, April 15th, 2013

One of the many scenarios that ReSharper seeks to address in web projects is a situation where the locations of files during the design of the app are different from the locations where the app gets deployed. This makes life difficult for ReSharper, since it doesn’t know where to go looking for the relevant files. Luckily, the Path Mapping feature lets you configure the locations of those paths.

There are two mechanisms that can both be used to configure path mappings – context actions and explicitly opening the Path Mapping dialog.

When ReSharper sees a path that it doesn’t recognize, it will underline the path with a wavy line, complaining that it doesn’t know where the path is. At this point, pressing Alt+Enter will show you several options for how the situation can be handled:

The first option, Ignore path, simply tells ReSharper to not bother inspecting this particular path wherever it may appear. This is useful in situations where, for example, you are referencing a file that doesn’t yet exist, and might be created later.

The second option is to Set path mapping, i.e. define explicitly how the path is handled.

Once again, there are two options: Substitute replaces a path with a different path, whereas Ignore chooses to ignore the path and is functionally equivalent to the Ignore path context action.

The Path mapping dialog box doesn’t only show up when you use a context action: you can also open it up by selecting the Path mapping element of the properties of the web project you’re working with. Note that we’re talking about the property grid (F4) rather than the tabbed property pages. To bring up the dialog, just press the button next to Path mapping.

Incidentally, the text value next to the button can be one of two possible options – either Custom indicating that some mappings have already been created, or Not set when none have yet been defined. At any rate, just as with the context action, pressing the button brings up the Path mapping window where you can create, delete and change mappings:

We hope you find this feature of ReSharper useful and your experience of developing web applications becomes a little more enjoyable. Develop with pleasure!

ReSharper and custom ASP.NET MVC view location

Tuesday, January 29th, 2013

Since ReSharper 5, we’ve had splendid support for ASP.NET MVC. One of the features included for ASP.NET MVC is Navigate to View and Create View. When working in an ASP.NET MVC action method, these methods allows us to either navigate to the corresponding view or create a view with the correct name at the correct location.

The interesting part of this feature is that ReSharper checks for assignments to the different properties on a ViewEngine, such as ViewLocationFormats and PartialViewLocationFormats, to determine the paths to various view types. This means it is possible to diverge from the default conventions in ASP.NET MVC and still make use of the ASP.NET MVC support ReSharper gives us.

Imagine having a project in which views are not located in the conventional Views folder but instead in another subfolder, like UI/MVC/Razor. We can do this in ASP.NET MVC by creating a new ViewEngine implementation and specifying a path template in the constructor:

To ensure ASP.NET MVC makes use of this custom ViewEngine, we must register it in Global.asax under Application_Start:

What’s interesting is that ReSharper immediately tells us no views can be found:

We can now move our views to the correct location or have ReSharper create them for us using the Create View feature. The new view will be located in our project under UI/MVC/Razor/Home/Index.cshtml.

Pretty slick if you ask me!

ASP.NET 4.5 and ASP.NET MVC 4 Support in ReSharper 7

Monday, September 24th, 2012

In spite of all the wonderful things happening in the Windows 8/WinRT world, ReSharper continues to provide support for existing technologies such as ASP.NET. In the latest release, ReSharper is augmented with new features for supporting ASP.NET 4.5 and ASP.NET MVC 4. Here’s what we’ve got in store.

ASP.NET 4.5

In ASP.NET 4.5, Web Forms support includes several improvements when working with data. Here are the ones that ReSharper now understands and supports:

  • Strongly Typed Data Controls — instead of using Eval() and Bind() for data binding, ASP.NET 4.5 lets developers declare the type of the element being bound via the ItemType property and provides the Item and BindItem properties inside binding expressions. ReSharper provides full support for these new constructs with code completion:
    ReSharper code completion for strongly typed data controls
    Inspections, fixes, refactorings and other typical ReSharper features are also supported:
    Code inspection for data binding

  • Model Binding — this mechanism lets one bind controls to data acquired from a particular function on the page, defined in the SelectMethod property. Once again, ReSharper provides typical features such as code completion…
    ReSharper code completion for model binding
    … as well as navigation, refactorings and other features typical for a C# property. Additionally, ReSharper is smart to check the return type of the SelectMethod and issue a warning if its type does not match that of the ItemType:
    ReSharper issues a warning it SelectMethod parameter type doesn't match that of ItemType

  • ReSharper is now also aware of HTML Encoded Data-Binding Expressions, which let developers add a colon (:) to the <%# prefix to ensure the subject of a data binding expression is HTML-encoded.

Of course, ReSharper also supports typical features such as code completion and validation inside the string literals that are used in the Eval() and Bind() methods.

ASP.NET MVC 4

ReSharper 7 extends its support for ASP.NET MVC to projects that use the ASP.NET Web API — the new framework for creating HTTP services. This means typical features such as inspections, navigation and refactorings are now available for Web API projects.

In addition, ReSharper now supports the Display Modes feature of MVC4, which lets an application select views depending on what browser makes the request. For example, ReSharper’s Go to Declaration on a view reference will show all the view files with different display modes:

ReSharper navigation support for ASP.NET MVC 4 Display Modes

In a similar fashion, performing a Find Usages on a view file with a display mode suffix will correctly locate its usages. Also, ReSharper is smart enough to detect when custom display modes are defined.

We hope you find these new ASP.NET-related features beneficial in your everyday development. Meanwhile, we continue to add more goodness to our support of the ASP.NET stack. Stay tuned for more!

ReSharper 5.1.2 is Released

Thursday, January 13th, 2011

ReSharper 5.1.2 bugfix campaign is finally over! Please download ReSharper 5.1.2 release build (5.1.1766.4) from the official ReSharper web site. It should work well with ASP.NET MVC 3 RTM that Microsoft is releasing today.

Here’s a quick overview of fixes and improvements introduced since version 5.1.1:

  • ReSharper 5.1.2 doesn’t interfere with Visual Studio IntelliSense in ASP.NET MVC 3 Razor syntax. Earlier ReSharper 5.x builds had certain issues with Razor IntelliSense that are addressed in 5.1.2. Specifically, ReSharper 5.1.2 doesn’t prevent Visual Studio from automatically providing its own IntelliSense in .cshtml and .vbhtml web pages anymore: both code completion and Parameter Info work as expected. Other than that, ReSharper 5.x doesn’t provide any additional support for Razor: only ReSharper 6 will bring full support for this view engine. Pre-release ReSharper 6 builds are currently available via Early Access Program.
  • Improved IntelliSense in Watch tool windows. The Razor IntelliSense fix has a side effect: ReSharper doesn’t anymore block Visual Studio IntelliSense from automatically popping up after dot in Watch tool windows used during debugging. This fix doesn’t yet apply to the QuickWatch dialog box though.
  • Live templates can now be saved one by one. Prior 5.x releases were able to save all live templates at once but, weirdly, weren’t saving them on Ctrl+S. Now you can save them one by one safely. Besides, saving templates doesn’t deselect them in the Template Explorer anymore (RSRP-90569).
  • Support for Test Projects (MSTest) re-targeted to .NET Framework 3.5. We have already blogged about this particular improvement.
  • A backport from ReSharper 6 allows faster processing of large files (10,000 LOC or more.)
  • ReSharper PowerToys should no longer throw exceptions that they used to throw with 5.1.1.
  • External Sources now reads PDB files in a better way.
  • Bug fixes related to referencing CoreCLR assemblies from Silverlight projects, comments in VB.NET, BizTalk projects, shortcut persistence, and references to SharpSVN.

This is a recommended upgrade, so don’t forget to download ReSharper 5.1.2 and give it a go.

Razor Intellisense and ReSharper

Thursday, November 11th, 2010

As many of you know, ReSharper enhances the behavior of ASP.NET and Visual Studio in general. Yesterday the ASP.NET team released ASP.NET MVC 3 Release Candidate. The release includes support for Intellisense and Syntax Highlighting for Razor View Engine. There is however an issue if you have ReSharper installed, as it currently does not support Razor. As much as we’d like to sim-ship support for Razor as it’s made available, this is not always possible. Nonetheless we are working hard to bring you Razor support for ReSharper, along with first class support for JavaScript and CSS (all the goodness of Code Inspections, Refactoring, Intellisense and more). However, this does not mean that you cannot use ReSharper and Visual Studio’s default Razor Intellisense today. In this post I’ll show you how to do this.

Choosing the type of Intellisense

ReSharper has two options when it comes to Intellisense. You can either continue to use the default Visual Studio Intellisense or use the enhanced ReSharper Intellisense. This is something that can be configured under ReSharper –> Options –> Intellisense –> General.

SNAGHTML1f3c146e

Since we currently do not support Razor what happens is that when inside a CSHTML file (Razor’s View Files), ReSharper doesn’t “understand” it and therefore does not automatically invoke Intellisense. However, you can work around this by manually invoking Intellisense. This is done by pressing Ctrl+Space:

image

Using this option, you continue to get the benefits of ReSharper enhanced Intellisense inside Visual Studio, and have default Visual Studio Intellisense inside Razor files. However, you do need to manually invoke it.

If you are not comfortable with this option, you can revert back to using Visual Studio’s Intellisense. All you need to do is select this option under the configuration displayed previous. This will then automatically invoke Intellisense for Razor files without the need to press Ctrl+Space. You can then manually invoke ReSharper Intellisense with Ctrl+Alt+Space

image

Default Editor

If Intellisense still does not work for you despite these two workarounds, make sure you have not associated the CSHTML files with an incorrect editor. Prior to RC of MVC 3, many users have been using HTML Editor as the default editor for CSHTML, which enabled them to get basic HTML Intellisense and Syntax highlighting. If you still have this option set, make sure you set it to use the new Razor Editor. To do this, right click on any CSHTML file and click on Open With, choosing Razor Editor

image

SNAGHTML1f47de61

Doing this should enable Intellisense inside Razor for you, and you continue to get the full benefits of ReSharper outside of Razor.

If you continue to have any issues with Intellisense, please leave a comment or contact us via the forums or Twitter.  And don’t forget you can learn more about ReSharper and our other tools at JetBrains TV