I have this HTML code to create a combobox from an enumerated
Enumerated
public enum tipoFormasPago
{
[Display(Name = "Efectivo")]
E,
[Display(Name = "Tarjeta")]
T,
[Display(Name = "Paypal")]
P
}
HTML code
<td>Forma de pago</td>
<td>
@Html.DropDownList(
"formaDePago",
EnumHelper.GetSelectList(typeof(testweb.Classes.EnumUtils.tipoFormasPago)),
"Selecciona",
new { @class = "formaDePago form-control" }
)
<span class="error">Forma de pago obligatoria</span>
</td>
If I look at the HTML with firebug I see the following:
<select class="formaDePago form-control" id="formaDePago" name="formaDePago">
<option value="">Selecciona</option>
<option value="0">Efectivo</option>
<option value="1">Tarjeta</option>
<option value="2">Paypal</option>
</select>
And from javascript I want to collect the value of the combobox, for this I have tried in these ways but I always receive "0"
:
var var1 = $('#formaDePago').find('option:selected').val();
var var2 = $('select[name=formaDePago]').val();
I would also like the values to be completed with the list I have created.
Thank you.