MVC数据类型货币触发数字键盘 [英] MVC Datatype Currency trigger numeric keypad

查看:160
本文介绍了MVC数据类型货币触发数字键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模型有一个Dataype(Datatype.Currency)whic是一个十进制对象。

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

我试图迫使该视图,当用户点击到它触发iPad / iPhone的数字小键盘。当对象是INT,但不会为十进制工作,它的工作原理。

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.

继承人的模型的片段(我已经使用常规的前pressions无济于事尝试过):

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; }

下面是该视图的一个片段。有没有使用新的方法{@inputtype =号}不知何故?

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.

推荐答案

EditorFor()方法不支持添加 htmlAttributes 除非您的使用MVC-5.1或更高版本。如果您是语法是

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

如果你没有,那么你就需要使用 TextBoxFor()方法添加属性

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

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

这篇关于MVC数据类型货币触发数字键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆