How to pass 2 values from my dropdown

Asked

Viewed 58 times

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 of form?

  • &#xA;[HttpPost]&#xA;public async Task<ActionResult> Index(ApiLServico.ContatoObject _user,&#xA;string cpf, string _ddd, string _telefone, int _agrupamentoId, string _agrupamentoNome)&#xA;{} this is the form Submit

  • Please, to add additional items in the post just use the [Edit] option. I refer in the View part, how the data is sent.

  • Sorry had not understood, it is a common POST using the tag method, inputs are controlled by name, updated with the form mount

  • 1

    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?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.