How to show a value in a select of an edit view (scafolding) from a model

0
<div class="form-group">
    @Html.LabelFor(model => model.Cantidad, htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        <select class="form-control" id="Cantidad" name="Cantidad">
            @* quiero que de acuerdo a la opcion que me trae el model, se seleccione el select *@
            <option value=1@(Model.Cantidad  == 1 ? "selected" : "")>Unidad</option>
            <option value=2@(Model.Cantidad  == 2 ? "selected":"")>Par</option>
            <option value=12@(Model.Cantidad == 12?"selected":"")>Docena</option>
        </select>
        @Html.ValidationMessageFor(model => model.Cantidad, "", new { @class = "text-danger" })
    </div>
</div>
    
asked by user8959730 26.06.2018 в 21:04
source

0 answers