asp.net-mvc html5 razor

asp.net mvc - Teclado numérico de activación de moneda de tipo de datos MVC



asp.net-mvc html5 (1)

Mi modelo tiene un Dataype (Datatype.Currency) que es un objeto decimal.

Estoy tratando de forzar la vista para activar un teclado numérico en ipad / iphone cuando el usuario hace clic en él. Funciona cuando el objeto es un INT pero no funcionará para Decimal.

Aquí hay un fragmento del modelo (he intentado usar expresiones regulares en vano):

[Display(Name = "Bid Price")] [DataType(DataType.Currency)] //[RegularExpression("([1-9][0-9]*)")] public decimal BidPrice { get; set; }

Aquí hay un fragmento de la vista. ¿Hay alguna forma de usar el nuevo {@inputtype = "number"} de alguna manera?

<div class="col-md-10"> @Html.EditorFor(model => model.BidPrice, new { @type= "number" }) @Html.ValidationMessageFor(model => model.BidPrice) </div>

Por favor, ayuda si alguna vez has conseguido que esto funcione.


El método EditorFor() no admite agregar htmlAttributes menos que esté utilizando MVC-5.1 o superior. Si usted es la sintaxis es

@Html.EditorFor(m => m.BidPrice, new { htmlAttributes = new { @type= "number" } })

Si no es así, deberá usar el método TextBoxFor() para agregar el atributo

@Html.TextBoxFor(m => m.BidPrice, new { @type= "number" })