【发布时间】:2014-07-04 18:15:53
【问题描述】:
我正在尝试在文本框中输入带小数点的数字,但收到错误 You must enter a valid value。
有人可以演示我如何修改下面的代码以确保只能在表单中输入带小数点和 2 位小数的真实价格。
还可以在字段前加上 £ (£) 字符,但显然在 post 提交的值中省略了 £ 符号?
Test.cs
[DisplayName("Amount")]
public Decimal Amount { get; set; }
Index.cshtml
@Html.TextBoxFor(m => m.Amount, new { @class = "form-control", type = "number", placeholder = "Amount", required = "required" })
【问题讨论】:
-
你在使用 Bootstrap 吗?如果是这样,我会将货币符号保留在文本框中,并使用 Bootstrap 输入组getbootstrap.com/components/#input-groups-basic
-
你可以试试 Html.EditorFor
-
我确实在使用 Boostrap。
-
如果我使用
@Html.EditorFor(m => m.Amount, new { @class = "form-control", placeholder = "Amount", required = "required" }),css 类不适用。 -
不能给EditorFor添加类,如果由于某种原因需要添加类,请改用TextBoxFor。
标签: c# html asp.net-mvc-4