0
I’m creating fields dynamically based on a List. When I remove a field, I need to reorder them using javascript, but I am facing problems, because all fields are reordered Indexes, except those that use Razor "Asp-validation-for"... Could I give 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");
});
Thank you @Victor Laio :)
– Master JR