2016-03-02 63 views
0

我的模型有一個Dataype(Datatype.Currency),它是一個小數對象。MVC數據類型貨幣觸發器數字小鍵盤

我試圖強制視圖觸發ipad/iphone上的數字小鍵盤,當用戶點擊進入它。它適用於對象是INT但不適用於Decimal的情況。

繼承人的模型的片段(我使用正則表達式無濟於事試過):

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

這裏是視圖的片段。有沒有辦法以某種方式使用新的{@inputtype =「number」}?

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

請幫助,如果你有這個工作。

+0

是的,這工作!我不知道我有多少網站試圖找到答案。謝謝!!! – dave317

回答

3

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

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

如果沒有,那麼你就需要使用TextBoxFor()方法來添加屬性

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