dotnet / dotnet/aspnetcore

Feature Request: View Component Slots

Open
#37,434 13 comments 58 reactions 0 assignees View on GitHub
area-mvc enhancement needs-prototype
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.

ASP.NET Mvc has never had a robust component model, the way Web Forms did. ASP.NET Core Tag Helpers and View Components have helped improve this story, but they still lack some composition patterns.

Creating container/wrapping markup is possible with Tag Helpers, but Tag Helpers are a C#-first approach to markup and container/wrapping markup is almost always related to visuals along with functionality. HTML is _far_ easier to maintain in Razor vs C# strings.

It would be helpful to be able to use View Components instead of Tag Helpers for container/wrapping markup when rendering common HTML that contain different children (as defined by the Razor calling the View Components).

I'm specifically requesting this for non-Blazor ASP.NET Core Razor HTML rendering and as a request for ASP.NET Core 7.

### Describe the solution you'd like

There is an existing proposal (and sample/demo repository) for this feature, but the original feature request is a locked issue:
https://github.com/dotnet/aspnetcore/issues/4901

Examples can be seen in the original issue, but here is a short one:

```razor
@* Index.cshtml *@

Card title with a Link


Lorem ipsum


Lorem ipsum


Lorem ipsum


```

```razor
@* ~/Components/Card/Default.cshtml *@



...




Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.