我在Age字段的元数据类中有以下代码,它被输入为int。
@Html.TextBoxFor(m => m.Age, new { @class = "form-control numeric", @placeholder = Html.DisplayNameFor(m => m.Age), @type = "number", @min = "16", @max = "99", @maxlength = "2" })
在我看来,我将字段定义为:
<input name="Age" class="form-control numeric" id="Age" type="number" maxlength="2" min="16" max="99" placeholder="Age" value="" data-val-required="Age is required" data-val-number="The field Age must be a number." data-val="true" data-val-range-min="16" data-val-range-max="99" data-val-range="Please specify an Age between 16 and 99">
在表单中,HTML呈现为:
Please enter a value greater than or equal to 16.
但是返回的错误消息是:
public String getUsername() {
return username;
}
public String getTimeString() {
return timeString(timestamp);
}
之前有没有其他人遇到此错误?
非常感谢任何帮助。感谢。
答案 0 :(得分:0)
解决。显然,当字段被定义为数字而不是文本字段时会发生这种情况。
我改变了:
@Html.TextBoxFor(m => m.Age, new { @class = "form-control numeric", @placeholder = Html.DisplayNameFor(m => m.Age), @type = "number", @min = "16", @max = "99", @maxlength = "2" })
到:
@Html.TextBoxFor(m => m.Age, new { @class = "form-control numeric", @placeholder = Html.DisplayNameFor(m => m.Age), @maxlength = "2" })
现在它就像一个冠军。