Can not type a double in a textbox

前端 未结 2 1494
野趣味
野趣味 2021-01-18 23:49

I\'m working on an mvc .net web application and I\'m using Entity Framework for generating Model. I have classes that contain attributes that are doubles. My problem is that

2条回答
  •  花落未央
    2021-01-19 00:35

    You could use add notations :

    [DisplayFormat(DataFormatString = "{0:#,##0.000#}", ApplyFormatInEditMode = true)]
    public double? Double_attribute{ get; set; }
    

    And now... voila : you can use the double in your view :

    @Html.EditorFor(x => x.Double_attribute)
    

    For other formats you could check this or just google "DataFormatString double" your desired option for this field.

提交回复
热议问题