I am working with ASP.NET MVC 5, I am in need of getting the value of Id
of Item
selected from DropDownList
, when I say value I refer to Id
not to Descripción
.
The DropDowList
is loaded as follows:
Controller
// GET: Proveedor/Create
public ActionResult Create()
{
var proveedor = SdProveedor.ListaTipoDocumentoIdentidad();
ViewBag.ListaProveedores = new SelectList(proveedor, "Id", "Descripcion");
var model = new ProveedorDto();
return View(model);
}
View
<div class="form-group">
@Html.LabelFor(model => model.DocumentoIdentidad, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("myDropDown", (SelectList)ViewBag.ListaProveedores)
</div>
</div>
Now I need to get the value of Id
Selected from DropDownList
, Would I have to create an event Changed
or something similar that when you select a Item
take the value and send it to the model to make the POST
?