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!
Subscribe to Blog updates
Thanks, we've got you!
Another Look into the Future with Rider’s Predictive Debugger
In the 2023.2 release cycle, we’ve introduced the Predictive Debugger in ReSharper, which gives you predictions about code paths and variables beyond the current execution pointer. We’ve written extensively about its advantages compared to alternative debugging strategies like thorough thinking, log…
Visualize Entity Framework Relationships and Additional Query Analysis in ReSharper 2023.3
A lot of teams are using Entity Framework or EF Core to work with their database. As an Object-Relational Mapper (ORM), it bridges objects in code to a relational database model, so that as a developer you don’t have to worry too much about the actual database. We all know: that’s not entirely tr…
Automatically Analyze ASP.NET Core Performance With Dynamic Program Analysis
Slow web pages may make your users or customers abandon your web application, even before they’ve had a proper look at it. You’ve likely also been frustrated working with a web application that is slow to load. The good news is that the latest versions of ReSharper and JetBrains Rider’s Dynamic P…
OSS Power-Ups: MassTransit – Webinar Recording
The recording of our webinar, OSS Power-Ups: MassTransit, with Chris Patterson, is available. This was the thirteenth episode of our OSS Power-Ups series, where we put a spotlight on open-source .NET projects. Subscribe to our community newsletter to receive notifications about future webinars.…