ReSharper and custom ASP.NET MVC view location

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!

About Maarten Balliauw

Maarten Balliauw is a Developer Advocate at JetBrains, working on .NET tools and Space. He focuses on .NET, Azure, web technologies and application performance. Maarten is a frequent speaker at various national and international events. In his free time, he brews his own beer. Follow him on Twitter or check out his personal blog.
This entry was posted in How-To's and tagged , . Bookmark the permalink.

17 Responses to ReSharper and custom ASP.NET MVC view location

  1. Robert Slaney says:

    Would be nice if you could explicitly tell R# what the new convention is. If the view engine configuration is NOT in the exact place the web project it doesn’t work.

    We use a ViewEngine class definition from another assembly and R# can’t discover it.

  2. Maarten.Balliauw says:

    @Robert R# uses assignments to ViewLocationFormats as the method of determining where views are located. Can you try doing this assignment in the web project?

    • Tudor says:

      I have the same problem as Robert Slaney. We created a custom razor view engine (which adds extra view locations) in another assembly because we have several mvc solutions using the same custom view engine. R# can’t find the view. It would be nice if there was an option to specify different view locations in R#.

  3. Kiliman says:

    I’ve got a method named RenderPartialViewToString(string viewName, object model).

    Is there a way to decorate that method so Resharper knows that it should look for views name viewName?

    That would be awesome.

  4. Maarten.Balliauw says:

    @Kiliman yes there is. Checkout on some attributes that are supported by ReSharper and allow you to do just that.

  5. David says:

    Does the same thing go for controllers. I am thinking of using the Single Action Controller idea and I am curious if there is some way to make sure resharper doesnt freak out.

  6. lifetime of e cig battery says: tool use 2.0 framework.In we are create a project then three language Vb,C# and R# file..C# is same as a in
    thanks give the info R#(resharper )

  7. Zache says:

    Is it possible for this feature to work using a ViewEnginge similiar to this?

  8. Maarten.Balliauw says:

    That will indeed work.

  9. Kijana Woodard says:

    “Zache Says:
    April 19th, 2013 at 3:45 pm
    Is it possible for this feature to work using a ViewEnginge similiar to this?

    Maarten.Balliauw Says:
    April 19th, 2013 at 5:54 pm
    That will indeed work.

    I tried it. It doesn’t appear to work. R# 7 creates a folder at “/%1/{ControllerName}/{ViewName}.cshtml”

  10. The %1 will indeed not work as R# is unable to figure that one out. If this is a requirement please file an issue at

  11. Kijana Woodard says:


    It’s a little different than the %1 case.
    Hopefully a little easier. :-]

  12. Jeff says:

    Is there a way to get this to work without clearing out the default view locations? The example I found online for a custom view engine did a union to merge the new custom format with the existing view locations. But when I do this resharper doesn’t recognize my new location. If I follow the example above and only set my new location then Resharper works for resolving views in the new location but Resharper (and .net) cannot find views still in the original locations.

    This is what I have in my custom view engine…

    private static readonly string[] NewViewFormats = new[]

    public CustomerAreaViewEngine()
    base.ViewLocationFormats = base.ViewLocationFormats.Union(NewViewFormats).ToArray();
    base.PartialViewLocationFormats = base.PartialViewLocationFormats.Union(NewViewFormats).ToArray();

  13. Unfortunately it will currently not work with the Union() in there. If you assign it a full array, this will work.

  14. Jeff says:

    Ok, I guess I’ll just have to copy the format strings from the base RazorViewEngine to use in my custom engine then. I was hoping to not have to copy and paste to re-use the default values but I couldn’t get it to recognize the new location anytime that I tried to combine it with the locations that were already added by the base view engine.

  15. Ben Mills says:

    I have a custom view engine that is NOT registered in global.asax, but Resharper still seems to be trying to use it instead of the the standard view engine. If I remove the custom view engine from the project, then I see no Resharper errors. As soon as I add it back, then Resharper shows 100’s of errors where it cannot resolve views and actions.

    My use case for the custom view engine is a little complex/confusing. I need it outside the scope of the regular ASP.NET MVC pipeline.

  16. Jeff W says:

    I ran across this recently in a large project after having to start on a fresh machine. Before going to this extreme, make sure your folder names are correct. You may not have to create a custom view engine.

    In my case, the Controller was:


    None of the functions in the controller could find their views — R# was reporting errors.

    Turns out a previous developer had put the views here, i.e.


    Changing the dash to an underscore in the folder name allowed R# to find the views. The system worked the other way (Razor itself was rendering the views and creating the models just fine). It was only R# that utterly depended on the folder name matching, which makes sense.

Leave a Reply

Your email address will not be published. Required fields are marked *