C#C
C#4y ago
Anton

❔ Abstracting html in Razor

I want to define custom components to abstract away some html content. These should be able to accept props, like key names, expressions, or pieces of html. For example:
<div class="a-bunch-of-tailwind-classes">
    <label class="a-bunch-of-classes" asp-for="Expression"/> DisplayName
    <input class="a bunch of classes" asp-for="Expression" some-validation-stuff type="Type"/>
</div>

should be produced from e.g.
<LabeledInput Expression="Model.Title" DisplayName="Title" Type="text"/>

or something like that. Should I make a bunch of tag helpers? I know that these can't be backed by html files. Partial views maybe?
I've read that razor components is something else, it's tightly coupled with blazor
Was this page helpful?