Remove Sets from EditorFor

2

I created my class with type int

[Required(ErrorMessage = "Preencha o Numero")]
[DisplayName("Numero")]
public int Number { get; set; }

  

Codeofview:

<!--Number--><divclass="alinhado col-md-4">
    <div class="form-group">
        <div class=" alinhadoLabel">
            @Html.LabelFor(model => model.Number,
                        htmlAttributes: new { @class = "control-label" })
        </div>
        <div class="alinhadoEditor">
            @Html.EditorFor(model => model.Number, 
                  new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Number, "", 
                  new { @class = "text-danger" })
        </div>
    </div>
</div>
<!--End Number-->
    
asked by anonymous 13.12.2016 / 03:48

2 answers

3

Place TextBoxFor instead of EditorFor . The TextBoxFor generates a input text , while EditorFor generates input ", depending on the type in your model that can be color , date , datetime , datetime-local , email , month , number , range , search , tel , time , url , and week which are actually Html5 Tags , that is, the EditorFor " generates input according to the type, it has advantages in this aspect, since has already been shown that if the type change automatically adapts to the new type, the type of input .

There is no way to get the arrows in your case, because EditorFor generates a input of this type:

<input type="number" name="Number" />

being a input of type number ( Html5 ) that has the characteristics of accepting numbers and the arrows a facility for the user to increase or decrease the existing value.

The only way around this is to put a TextBoxFor that generates a input like this:

<input type="text" name="Number" />

which is in this case a input simple of type text .

References:

13.12.2016 / 04:10
1

Another way is to add this CSS code:

input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance:textfield;
}

Retired this SO response .

    
13.12.2016 / 14:32