Foundation project: Cannot resolve View

Vote:
 

When I go to any of the controllers (e.g. HomeController), View is highlighted as red (Visual Studio 2022) saying:

Cannot resolve view 'Index'

Is that because the Features structure is not configured for static analysis?

What's the way to solve it?

#284049
Jul 21, 2022 11:23
Vote:
 

Are you using ReSharper? I also get this error, but only when using ReSharper. The only option I'm aware of is to change the error severity — for example the 'Do not show' option will hide the message entirely.

Or in the options menu:

#284195
Edited, Jul 22, 2022 0:18
Vote:
 

Thank you for the answer, Ynze.

I was able to fix it with a slightly different approach:

  1. Added ResharperConfig.cs (the file name doesn't matter) to the root of the project.
  2. Added the following code:

Added `ResharperConfig.cs` with the following content:

using JetBrains.Annotations;

[assembly: AspMvcViewLocationFormat("/Features/Shared/{0}.cshtml")]
[assembly: AspMvcViewLocationFormat("/Features/Blocks/{0}.cshtml")]
[assembly: AspMvcViewLocationFormat("/Features/Blocks/{1}/{0}.cshtml")]
[assembly: AspMvcViewLocationFormat("/Features/Shared/Views/{0}.cshtml")]
[assembly: AspMvcViewLocationFormat("/Features/Shared/Views/{1}/{0}.cshtml")]
[assembly: AspMvcViewLocationFormat("/Features/Shared/Views/Header/{0}.cshtml")]
[assembly: AspMvcViewLocationFormat("/Cms/Views/{1}/{0}.cshtml")]
[assembly: AspMvcViewLocationFormat("/Features/{3}/{1}/{0}.cshtml")]
[assembly: AspMvcViewLocationFormat("/Features/{3}/{0}.cshtml")]
[assembly: AspMvcViewLocationFormat("/Features/{3}/{4}/{1}/{0}.cshtml")]
[assembly: AspMvcViewLocationFormat("/Features/{3}/{4}/{0}.cshtml")]
[assembly: AspMvcViewLocationFormat("/Features/Shared/Views/ElementBlocks/{0}.cshtml")]

[assembly: AspMvcAreaPartialViewLocationFormat("/Features/Shared/{0}.cshtml")]
[assembly: AspMvcAreaPartialViewLocationFormat("/Features/Blocks/{0}.cshtml")]
[assembly: AspMvcAreaPartialViewLocationFormat("/Features/Blocks/{1}/{0}.cshtml")]
[assembly: AspMvcAreaPartialViewLocationFormat("/Features/Shared/Views/{0}.cshtml")]
[assembly: AspMvcAreaPartialViewLocationFormat("/Features/Shared/Views/{1}/{0}.cshtml")]
[assembly: AspMvcAreaPartialViewLocationFormat("/Features/Shared/Views/Header/{0}.cshtml")]
[assembly: AspMvcAreaPartialViewLocationFormat("/Cms/Views/{1}/{0}.cshtml")]
[assembly: AspMvcAreaPartialViewLocationFormat("/Features/{3}/{1}/{0}.cshtml")]
[assembly: AspMvcAreaPartialViewLocationFormat("/Features/{3}/{0}.cshtml")]
[assembly: AspMvcAreaPartialViewLocationFormat("/Features/{3}/{4}/{1}/{0}.cshtml")]
[assembly: AspMvcAreaPartialViewLocationFormat("/Features/{3}/{4}/{0}.cshtml")]
[assembly: AspMvcAreaPartialViewLocationFormat("/Features/Shared/Views/ElementBlocks/{0}.cshtml")]

3. Then, I rebuilt the solution
4. ...and restarted Visual Studio.

And... it works fine now :)

#284207
Jul 22, 2022 9:32
Ynze - Jul 22, 2022 10:25
Nice solution, thank you!
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.