In a lof of my .NET Core MVC forms, I have code like this for every text field:
<div class="form-group">
<label class="col-form-label" asp-for="Field1">Field 1</label>
<input asp-for="Field1" class="form-control" tabindex="1" autofocus />
<span asp-validation-for="Field1" class="text-danger small"></span>
</div>
This code is always the same and I was wondering if I could create a partial view that I can re-use every time I wanted to place a text field on a form.
My end goal would be something like this: (pseudo-code)
@Html.RenderPartial("TextField", Model.Field1)
@Html.RenderPartial("TextField", Model.Field2)
Any validation attributes on Field1
or Field2
would still have to work though. How would I go about passing this information on? Is there a way?