【问题标题】:MVC Datatype Currency trigger numeric keypadMVC 数据类型货币触发器数字键盘
【发布时间】:2016-06-14 16:11:56
【问题描述】:

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

我试图强制视图在用户单击它时触发 ipad/iphone 上的数字键盘。当对象是 INT 但不适用于 Decimal 时,它可以工作。

这是模型的 sn-p(我尝试使用正则表达式无济于事):

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

这是视图的 sn-p。有没有办法以某种方式使用新的 { @inputtype = "number"}?

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

如果你曾经得到这个工作,请帮忙。

【问题讨论】:

  • 是的,有效!我不知道我查看了多少网站来尝试找到答案。谢谢!!!

标签: asp.net-mvc html razor


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 2014-03-25
    • 1970-01-01
    相关资源
    最近更新 更多