dotnet / dotnet/aspnetcore

Partial views as tag helpers for Razor Pages

Open
#40,563 2 comments 5 reactions 0 assignees View on GitHub
area-mvc enhancement
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

The `` tag helper works OK for partial views that take a single parameter, but it requires hacks like using a tuple as the model (which isn't particularly readable and can have type conversion issues) when the partial view needs multiple parameters.

### Describe the solution you'd like

It would be great if a custom tag helper could be defined by using a Razor Pages-style object model. For example, suppose that the file FooBar.cshtml was placed into the TagHelpers folder with the following code:

```
@tagHelper "foo-bar"
@model FooBarModel


First Thing: @Model.FirstThing


Second Thing: @Model.SecondThing


```

Suppose that it had a code-behind file FooBar.cshtml.cs as follows

```
public class FooBarModel
{
[TagHelperProperty("first-thing")]
public string FirstThing { get; set; }

[TagHelperProperty("second-thing")]
public string SecondThing { get; set; }
}
```

If a Razor Page invoked the tag helper as follows:

```

```

Then, the result would be rendered as follows:

```


First Thing: ABC


Second Thing: XYZ


```

### Additional context

_No response_

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.