Feature Request: Custom View Component View paths
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Is your feature request related to a problem? Please describe.
The current View Component View path is hardcoded as a format string
https://github.com/dotnet/aspnetcore/blob/v5.0.10/src/Mvc/Mvc.ViewFeatures/src/ViewComponents/ViewViewComponentResult.cs
```csharp
public class ViewViewComponentResult : IViewComponentResult
{
// {0} is the component name, {1} is the view name.
private const string ViewPathFormat = "Components/{0}/{1}";
private const string DefaultViewName = "Default";
// ...
```
This means that to really customize the path of View Components we need to create a custom `IViewComponentResult` implementation, copy a bunch of code from ASP.NET Core into our apps, keep that up to date, and then use that custom `IViewComponentResult` throughout our codebase.
This has already been mentioned in an existing, but locked issue:
https://github.com/dotnet/aspnetcore/issues/10277
(also related to https://github.com/dotnet/aspnetcore/issues/26911)
`IViewLocationExpander` can fully customize the paths for Controller and Partial Views, but not View Components because of this hardcoded value.
Our team organizes ASP.NET Core components by "Feature Folders" and sometimes we have nested or, generally more complex folder structures for larger server-side HTML rendered applications, but we are limited by this hardcoded value in this area of the framework.
### Describe the solution you'd like
This value should be customizable at the application level, possibly through `MvcOptions` so that View Components have the same organizational flexibility as other parts of the framework.
### Additional context
If a default value was set, but customization was allowed, existing applications would not be affected and developers could customize the organization of their files per app (or team).
This is a request for improvements being considered for ASP.NET Core 7.
Contributor guide
Assessment
This issue has not been assessed yet.