MVC Inspection cannot resolve views / partial views / actions / controllers etc.

It seems like R# cannot resolve any MVC locations within my project, flagging any references as errors (e.g. cannot resolve view 'viewname' etc.)

I am using R# 2017.3.1 on VS 2015.

I have an MVC subfolder within my project, with Controllers / Models / Views Subfolders.

I'm also using MvcCodeRouting - not sure if that could impact.

It seems like R# doesn't know where to look for any MVC assets... is there something I need to do to tell it "MVC" is in this folder "Controllers are in this folder" etc...?

 

Thanks for your help.

Dan.

1
4 comments

Ok... just a bit more info...

Within my controller 'APPRootNamespace.MVC.Controllers.Personal.TimesheetController' I have an ActionResult method that returns:

'return View("TimesheetBase", model);'

The TimeSheetBase view is within 'APPRootNamespace.MVC.Views.Personal.Timesheet'

When I tell R# to 'Create Razor View' it gets placed within 'APPRootNamespace.MVC.Views.Timesheet'

This seems to me that R# MVC Inspection is not compatible with MvcCodeRouting based on Namespaces...

Can anyone confirm this - is there a workaround, or am I best just disabling ASP.NET MVC inspection for now? 

0

Hello Dan!

 

Sorry for delay in responding.

ReSharper doesn't work with routing in general as it's a static code analyzer, it cannot run the code.

As a workaround you may try JetBrains.Annotations and adding AspMvcViewLocation, AspMvcPartialViewLocation attributes to your code.

Thank you.

1

Thanks for your response.

Are you able to point me to anywhere documenting with examples how I would do this to solve this particular issue - a quick search for AspMvcPartialViewLocation attribute did not pull anything up...

0

Hello Dan!

 

Then, you need to add some of these assembly level attributes (usually in your AssemblyInfo.cs, but it can be anywhere):

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


You can add more than one of each type, and you'd use them like this:

[assembly: AspMvcViewLocationFormat("~\Admin\Views\{1}\{0}.aspx")]
[assembly: AspMvcViewLocationFormat("~\Admin\Views\{1}\{0}.ascx")]
[assembly: AspMvcViewLocationFormat("~\Admin\Views\{1}\{0}.cshtml")]
[assembly: AspMvcViewLocationFormat("~\Admin\Views\Shared\{1}\{0}.aspx")]
[assembly: AspMvcViewLocationFormat("~\Admin\Views\Shared\{1}\{0}.ascx")]
[assembly: AspMvcViewLocationFormat("~\Admin\Views\Shared\{1}\{0}.cshtml")]


And so on, for views, partial views, masters and for when you're in an area. The replacement values are:

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


ReSharper will use these path format strings to look for the different views.

0

Please sign in to leave a comment.