Created
November 24, 2022 17:37
-
-
Save JuergenGutsch/a70d21d034cc1d766dc744031f003659 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PersonGridTagHelper : TagHelper | |
{ | |
[HtmlAttributeName("persons")] | |
public IEnumerable<Person> Persons { get; set; } | |
public override void Process(TagHelperContext context, TagHelperOutput output) | |
{ | |
output.TagName = "table"; | |
output.Attributes.Add("class", "table"); | |
output.Content.AppendHtml("<tr>"); | |
output.Content.AppendHtml("<th>First name</th>"); | |
output.Content.AppendHtml("<th>Last name</th>"); | |
output.Content.AppendHtml("<th>Age</th>"); | |
output.Content.AppendHtml("<th>Email address</th>"); | |
output.Content.AppendHtml("</tr>"); | |
foreach (var person in Persons) | |
{ | |
output.Content.AppendHtml("<tr>"); | |
output.Content.AppendHtml($"<td>{person.FirstName}</td>"); | |
output.Content.AppendHtml($"<td>{person.LastName}</td>"); | |
output.Content.AppendHtml($"<td>{person.Age}</td>"); | |
output.Content.AppendHtml($"<td>{person.EmailAddress}</td>"); | |
output.Content.AppendHtml("</tr>"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment