How to pass a parameter along with the Model to a PartialVIew when rendering it

1

To create some fields dynamically, I'm using a for and rendering. When calling Partial _Contact, I would like to pass the value [i] of the index of for so I can sort the fields. It's not working ... You're giving the page error ... does anyone know how to help me? A hug!

Error:

Generatingthefields:

@for(inti=0;i<Model.PessoasContatosViewModel.Count;i++){@awaitHtml.PartialAsync("_Contato", Model.PessoasContatosViewModel[i], new ViewDataDictionary { { "indice", i } })
}

Receiving the Model and Parameter in PartialView _Contact:

@model Retaguarda.Application.ViewModels.Pessoa.PessoaContatoViewModel
@{
    string valuePassedIn = this.ViewData.ContainsKey("indice") ? this.ViewData["indice"].ToString() : "0";
}
    
asked by anonymous 23.10.2018 / 23:52

1 answer

1

Switch:

@await Html.PartialAsync("_Contato", Model.PessoasContatosViewModel[i], new ViewDataDictionary { { "indice", i } })

By:

   @await Html.PartialAsync("_Contato", Model.PessoasContatosViewModel[i], new ViewDataDictionary(ViewData){ { "indice", i } })
    
24.10.2018 / 00:34