C
C#2y 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>
<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"/>
<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
3 Replies
Anton
Anton2y ago
Passing down ModelExpressions to partial views or tag helpers results in a massive jump in complexity
Anton
Anton2y ago
Stack Overflow
Pass ModelExpression from a Tag Helper to a Partial View
I'm using the example found here to allow the rendering of a partial view from within a tag helper. What I'm going for here is to be able to define a tag helper like so: <mydateinput for="@Model.
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.