MVC Datatype Currency trigger numeric keypad

2019-01-07 01:19发布

My Model has a Dataype(Datatype.Currency) whic is a decimal object.

I am trying to force the view to trigger a Numeric keypad on ipad/iphone when the user clicks into it. It works when the object is an INT but will not work for Decimal.

Heres a snippet of the model (I've tried using regular expressions to no avail):

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

Here is a snippet of the view. IS there a way to use the new { @inputtype = "number"} somehow?

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

Please help if you have ever got this to work.

1条回答
Ridiculous、
2楼-- · 2019-01-07 01:39

The EditorFor() method does not support adding htmlAttributes unless your using MVC-5.1 or higher. If you are the the syntax is

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

If your not, then you will need to use the TextBoxFor() method to add the attribute

@Html.TextBoxFor(m => m.BidPrice, new { @type= "number" })
查看更多
登录 后发表回答