我已閱讀關於此主題的許多帖子,但我仍在與我的問題作鬥爭。我有一個具有14個屬性和5個複雜類型的自定義模板編輯器的表單。客戶端驗證適用於所有屬性和自定義模板編輯器,但以下屬性。如果我輸入文本,它將刪除文本框中的所有內容,而不會顯示任何消息。但是,如果我輸入2.,我收到錯誤消息,說它必須是一個數字。有沒有人經歷過這種行爲?這也發生在我的其他一些形式上。.NET MVC客戶端驗證在值無效時不顯示屬性消息
作爲一個方面說明:客戶端應驗證可空的int範圍?似乎它不,除非我添加範圍驗證程序。謝謝。
UPDATE 這實際上是所有我的int?性能
型號
[Display(Name = "Lifetime")]
public int? Life { get; set; }
查看
@using (Html.BeginForm("EditPerson", "Maintenance", FormMethod.Post, new { @class = "operation-form" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(model => model.PersonId)
@Html.Hidden("ModifiedBy", User.Identity.Name)
<div class="form-horizontal">
@Html.ValidationSummary(false, "", new { @class = "text-danger" })
<div class="col-md-4">
<div class="row person-field">
<div class="col-md-6 field-name">
@Html.LabelFor(model => model.Life)
</div>
<div class="col-md-6">
@Html.EditorFor(model => model.Life, new { htmlAttributes = new { @class = "to-center routebox" } })
@Html.ValidationMessageFor(model => model.Life, "", new { @class = "text-danger" })
</div>
</div>
</div>
</div>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
你是對的,你必須使用範圍驗證器 – 2014-11-03 18:17:57