© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
3 replies
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

HTML Templating Scriban / Razor / Stubble / Fluid etc
C#CC# / help
9mo ago
✅ I need in help. How to use razor as html templater.
C#CC# / help
2y ago
❔ Razor MVC
C#CC# / help
3y ago
✅ Access wwwroot in Blazor wasm razor
C#CC# / help
4y ago