Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

asp.net mvc - MVC Datatype Currency trigger numeric keypad

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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" })

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...