0
I’m trying to send 2 values returned from my dropdown for my action, but I’m not finding a solution.
My dropdown lists the results of a query in the database and returns 2 values per item, I want to send both to my action
[HttpPost]
public List<ApiLServico.NivelGrupoObject> Form_Load()
{
int idGp = Convert.ToInt32(ConfigurationManager.AppSettings["IdGrupoAgente"]);
var retorno = api.ListarNiveis(idGp);
List<ApiLServico.NivelGrupoObject> agrupamentos = new List<ApiLServico.NivelGrupoObject>();
for (var i = 0; i < retorno.Length; i++)
{
ApiLServico.NivelGrupoObject nivel = new ApiLServico.NivelGrupoObject()
{
Id = retorno[i].Id,
Nome = retorno[i].Nome
};
agrupamentos.Add(nivel);
}
return agrupamentos;
}
My action gets the full form
[HttpPost]
public async Task<ActionResult> Index(ApiLServico.ContatoObject _user,
string cpf, string _ddd, string _telefone, int _agrupamentoId, string _agrupamentoNome)
{}
<form method="POST" style="max-width:700px; margin:auto;">
.... (outros campos)
<div class="col-md-12 form-group">
@Html.DropDownList("Niveis")
</div>
<div class="form-group text-center">
<button type="submit" class="btn btn-primary" style="width:128px">Cadastrar</button>
</div>
The values I want to send are agrupamentoId = Id do dropdown
and agrupamentoNome = Nome do dropdown
How do I send both values to my form?
How is the
Post
ofform
?– Barbetta

[HttpPost]
public async Task<ActionResult> Index(ApiLServico.ContatoObject _user,
string cpf, string _ddd, string _telefone, int _agrupamentoId, string _agrupamentoNome)
{}
this is the form Submit– Matheus Batista
Please, to add additional items in the post just use the [Edit] option. I refer in the View part, how the data is sent.
– Barbetta
Sorry had not understood, it is a common POST using the tag
method
, inputs are controlled byname
, updated with the form mount– Matheus Batista
hum. I don’t know a simple way to do this (only with "gambiarra"), but client side data may not be "reliable", it no longer pays to send the ID and in your Action search the data in the database?
– Barbetta