correct way to make a text box in mvc c #

1

I have my text box of type int in my view my leaves like this with the arrows up and down, as I declare so it does not look like this, or how I can put a dropndownlist with the years there.

 <div class="editor-label">
            @Html.LabelFor(model => model.Gestion, "Gestión")
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Gestion)
            @Html.ValidationMessageFor(model => model.Gestion)
        </div>
    
asked by Rodrigo Rodriguez 24.10.2017 в 16:56
source

1 answer

2

The default editor for a property of type int is a input of numeric type.

How it is displayed (with or without arrows) is a matter of the browser.

If you want to use a different editor, you must indicate it specifically. For example if, as you say, you want to do a drop down to select a year you could do something like this:

<div class="editor-label">
    @Html.LabelFor(model => model.Gestion, "Gestión")
</div>
<div class="editor-field">
    @Html.DropDownListFor(model=> model.Gestion, Enumerable.Range(1950, 100).Select(x=> new SelectListItem {Text= x.ToString()}))
    @Html.ValidationMessageFor(model => model.Gestion)
</div>

This would show a drop-down with 100 values from 1950.

    
answered by 24.10.2017 / 17:19
source