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.
Please sign in to leave a comment.
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.
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:
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
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?
Having the same issue with all our projects. I'ts reporting me over 1000 Errors that it cannot resolve the view "index" altough it IS there..
Really really annoying.
It's really had to figure out which error of this false positives is the real error ??:-(
We have our views organized like this:
e.g.:
Areas\SystemOverview\SystemState\SystemStateController.cs
Areas\SystemOverview\SystemState\SystemStateViewModel.cs
Areas\SystemOverview\SystemState\Views\Index.cshtml
Areas\SystemOverview\SystemState\Views\_Grid.cshtml
and a viewlocationexpander is configured like this:
// {0} - Action Name
// {1} - Controller Name
// {2} - Area name
"/Areas/{2}/{1}/Views/{0}.cshtml",
Hello B Held
Could you please try clearing caches as described in the following article - https://resharper-support.jetbrains.com/hc/en-us/articles/206546989 and let us know if it helps?
Thank you.
Good morning. Sorry for late answer. I tried out clearing caches but this did not led to any change. Still over 1000 errors.
Hello B Held,
Thanks for the reply. It looks like you have an unusual structure here: "/Areas/{2}/{1}/Views/{0}.cshtml". This is why you get a lot of errors. We have the following issue about that, please comment or vote for it to get notifications about status changes.
As a workaround, please use "Alt+Enter" on the problem view name and change the inspection severity ("Inspection: 'MVC' | Configure inspection severity"). Please let me know if you have any questions. Thank you!
B Held, I decided to submit a new issue in our bug tracker, so that each case is in a separate place. So, here it is. Please comment/vote for it. Thank you!
B Held are there ViewComponents not resolved in your project? Or regular views?
Another occurance with the same error:
Updated from 2023.1 to 2023.3
Old version did not show any errors, new version does.
We have a ViewComponent with default view in default place (/Shared/Components/<ComponentName>/Default.cshtml) used with more than one controller. All controllers provide the same “UserAction” action.
<button type="submit" asp-action="UserAction" … >
generates Mvc.ActionNotResolved error.- If I add "asp-controller' helper error disappears. But I can't do this, because the component should use the action provided by a parent controller, not a predefined one.
- If I use “@* ReSharper disable once Mvc.ActionNotResolved *@” directive, error is ignored, but not every one uses JetBrains IDE & tools and it is seen as code pollution.
Hello Joanna, thank you for your question. I've logged a new issue in our bug tracker regarding this behavior. Feel free to add your comments or vote on it to receive updates on its status. Also, if possible, please attach a sample solution to YouTrack issue so that we can fix the specific behavior you are experiencing. Thank you!