MVC ViewComponent default view not resolved unless it is in the shared folder.


MVC ViewComponent default view is not resolved unless it is in the shared folder.

Source code is available in the following github repo. 

Just as an example in the M2-Intro-To-THs-And-VCs project 

placing the components folder in shared folder of views the view gets resolved.

Comment actions Permalink

I played a lot with the assembly attributes in JetBrains.Annotaions. They (at least used to) work with PartialViews and anything that has Controller{1} and Action{0}. However they won't work for ViewComponents. 

The funny thing is that when I use something like this:

[assembly: AspMvcPartialViewLocationFormat(@"/full-path-to-the-features-folder/ComponentFolderName/Default.cshtml")]

It will fix that component. And because it is hard coded to point to that component only, all other components try to point to the same Default.cshtml.

I wish {0} and {1} was working here like the way that they work in PartialViews 

[assembly: AspMvcPartialViewLocationFormat(@"/full-path-to-the-features-folder/{1}/Default.cshtml")]
[assembly: AspMvcPartialViewLocationFormat(@"/full-path-to-the-features-folder/{1}/{0}.cshtml")]



Comment actions Permalink

Also having this issue. Any default views for ViewComponents under the Shared folder work fine and return no errors. However, any ViewComponent with a default view not under the Shared folder flags an error.

~/Views/{Controller}/Components/{ViewComponent}/Default.cshtml <- produces an error

~/Views/Shared/Components/{ViewComponent}/Default.cshtml <- seems fine, no errors

The weird thing is, if I use the context menu to create the "missing" view, it creates it in my unit test project for some reason under ~/Pages/Components/{ViewComponent}/Default.cshtml

Any ideas?

Comment actions Permalink


thank you all for the feedback.

I've filed a corresponding bug report - Please follow it to get the latest updates on the issue.

Thank you.


Please sign in to leave a comment.