Skip to content

View Components Search Path #10436

Closed
Closed
@mysteryx93

Description

@mysteryx93

I'm looking into View Components and am a bit confused as to where to put the files in my project.

For now, I have Pages\Shared containing partials starting with underscore, and ViewComponents without underscore, and decided to put the model they use next to it. So I have

  • _PartialView1.cshtml
  • Component1.cs
  • Component1Model.cs
  • Components\Component\Default.cshtml

I'm also hesitating about the namespace: put ViewComponents in MyWebsite.Pages.Shared or in MyWebsite.ViewComponents?

Because I don't like file hierarchy digging too deep (Pages\Shared\Components\Component1\Default, I'm thinking it would make more sense to put ViewComponents in the folder \ViewComponents next to Pages, Views, Models and Areas folders, especially since they carry many files and folders that go with them. That keeps the Shared folder and the overall project layout a lot cleaner.

Then I'd have View Components in \ViewComponents in namespace MyWebsite.ViewComponents, and everyone is happy and there's no confusion.

Problem is, the default search path does not include \ViewComponents.

Wouldn't it make sense to include \ViewComponents in the default search path?

Metadata

Metadata

Assignees

Labels

✔️ Resolution: DuplicateResolved as a duplicate of another issuearea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing one

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions