C # Razor HTMLHelper Dropdown

0

Friends I'm doing a drop down list with Razor and I'm trying to get the drop values, but I only get the name that I put in place of their values someone could guide me or tell me where I am wrong?

        [HttpPost]        
        public void  GetBanco() {
                
                string[] keys = Request.Form.AllKeys;
                string banco = keys[0]; // aquí el valor de banco es dropList
                // D: wtf?
                
                AddBanco(banco);
        //end method
        }
<div class="col-md-4">
  @using (Html.BeginForm("GetBanco", "Control", FormMethod.Post, new { enctype = "multipart/form-data" })) {
  <label>Elija un banco:</label> @Html.DropDownList("dropList", new SelectList(new[] { "Bancomer", "Banamex", "Santander", "Banorte" }), new { required = "required" })

  <input type="submit" value="cargar" /> }

</div>
    
asked by E.Rawrdríguez.Ophanim 17.05.2018 в 18:22
source

1 answer

1

You have to receive it as a FormCollection

for example;

[HttpPost]        
//Recibis un objeto FormCollection
public void  GetBanco(FormCollection form) {
    //"dropList" es el atributo name del input/select que queres recibir
    string banco = form["dropList"].ToString();
    AddBanco(banco);
}

Greetings

    
answered by 17.05.2018 / 18:43
source