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

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

问题描述

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

我试图强制视图在用户单击时触发 ipad/iphone 上的数字键盘.当对象为 INT 时有效,但不适用于 Decimal.

这是模型的一个片段(我试过使用正则表达式无济于事):

 [Display(Name = "Bid Price")][数据类型(数据类型.货币)]//[RegularExpression("([1-9][0-9]*)")]公开十进制 BidPrice { 获取;放;}

这是视图的片段.有没有办法以某种方式使用新的 { @inputtype = "number"} ?

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

如果您曾经使用过它,请帮忙.

解决方案

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

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

如果不是,则需要使用 TextBoxFor() 方法添加属性

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

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.

解决方案

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

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

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