不能键入文本框双 [英] Can not type a double in a textbox

查看:143
本文介绍了不能键入文本框双的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个MVC的.NET Web应用程序,我使用实体框架生成模型。我有一个包含双打属性类。我的问题是,当我使用 @ HTML.EditorFor(型号=> model.Double_attribute)和测试我的应用程序不能在编辑器中键入双,我只可以输入整数。 (我用剃刀引擎视图)如何解决此问题?谢谢你。

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 when I use @HTML.EditorFor(model => model.Double_attribute) and test my application I can't type a double in that editor, I only can type integers. (I'm using Razor engine for views)How to solve this? Thanks.

更新:我发现我可以键入双具有这种格式#,###(逗号后3个数字,但我不希望使用户输入特定的格式,我要接受所有的格式(1或更多逗号后的数字)
有没有人有一个想法如何解决这个问题?问候

Update : I discovered that I can type a double having this format #,### (3 numbers after the comma but I do not want to make user type a specific format, I want to accept all formats (1 or more numbers after the comma) Does anyone have an idea how to solve this? Regards

推荐答案

您可以使用添加符号:

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)

对于其它的格式,你可以检查<一href=\"http://stackoverflow.com/questions/7375729/mvc3-3-decimal-places-on-type-double-with-leading-zero\">this或者只是谷歌双DataFormatString此字段所需选项。

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

这篇关于不能键入文本框双的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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