How to fix when ReSharper says "Cannot resolve partial view"

By Markus Johansson
2018-11-05

This is a quite annoying problem that I sometimes hit with Resharper, some of the times the views are in the “correct” folders and sometimes when we’re using custom locations for the views.

Fortunately it can be fixed.

Use annotations to indicate where views are placed

Jetbrains ships a package of annotations that we can use to tell Resharper where our views are placed. Start by referencing the Nuget-package that contains these annotations:

Install-Package JetBrains.Annotations

Then in your solution, open the “Properties/AssemblyInfo.cs”-file and add these annotations to indicate for Resharper where you views are placed.

[assembly: AspMvcPartialViewLocationFormat(@"~\Views\Partials\{0}.cshtml")]
[assembly: AspMvcPartialViewLocationFormat(@"~\Views\MacroPartials\{0}.cshtml")]
[assembly: AspMvcViewLocationFormat(@"~\Views\{1}.cshtml")]

The example above works good with views in Umbraco CMS where some partials are placed in the "MacroPartials"-folder.

There’s three different placeholders that you can use to build the paths:

  • {0} - view name
  • {1} - controll name
  • {2} - area name

And there is also different annotations depending on what type of view we are looking for:

  • AspMvcAreaMasterLocationFormatAttribute
  • AspMvcAreaPartialViewLocationFormatAttribute
  • AspMvcAreaViewLocationFormatAttribute
  • AspMvcMasterLocationFormatAttribute
  • AspMvcPartialViewLocationFormatAttribute
  • AspMvcViewLocationFormatAttribute

Sometimes you beed to build and reload the projects for this to work.






More blog posts



15 januari 2021

Umbraco and MiniProfiler