I am creating fields dynamically based on a List. When I remove a field, I need to reorder them using javascript, but I'm facing problems since all fields are reordered in the Indexes, except those using the "asp-validation-for" razor ... Would I have a Find and change his Index too?
Razor:
<div class="col-md-2">
<label asp-for="PessoaFisicaViewModel.PessoasFisicasDocumentosViewModel[i].Documento" class="control-label txt-documento">Documento</label>
<input type="text" asp-for="PessoaFisicaViewModel.PessoasFisicasDocumentosViewModel[i].Documento" class="form-control txt-documento" />
<span asp-validation-for="PessoaFisicaViewModel.PessoasFisicasDocumentosViewModel[i].Documento" class="text-danger txt-documento"></span>
</div>
JavaScript:
$(this).parent().parent().remove();
qtdDocumentos--;
$("#div-documentos .row").each(function (indice, elemento) {
$(elemento).find(".txt-documento").attr("name", "PessoaFisicaViewModel.PessoasFisicasDocumentosViewModel[" + indice + "].Documento");
});