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

Answered

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

Source code is available in the following github repo.

https://github.com/pkellner/pluralsight-course-aspnet-taghelpers-viewcomponents.git 

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.

3 comments
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")]

 

 

0
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?

0
Comment actions Permalink

Hello,

thank you all for the feedback.

I've filed a corresponding bug report - https://youtrack.jetbrains.com/issue/RSRP-488797. Please follow it to get the latest updates on the issue.

Thank you.

0

Please sign in to leave a comment.