我在MVC 5中有一個表單。我需要在表單上有三個下拉列表。當我提交表單時,出現錯誤消息。問題是,當我從下拉列表中選擇值時,錯誤消息仍然顯示。然後,如果我提交按鈕,所需的錯誤消息消失。MVC立即驗證不會觸發?
主要問題是立即驗證不起作用。這種情況發生時,我第一次提交沒有選擇的表單,然後我選擇下拉值。錯誤仍然顯示。 這是我的表格。
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.HiddenFor(model => model.ProcessId)
<div class="row">
<div class="col-sm-6">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
</div>
</div>
<div class="row">
<div class="col-sm-12 bgnMrgn">
<div class="col-sm-12">
<h3>@Resources.BasicInformtion</h3>
</div>
<div class="form-group col-sm-2">
<label class="control-label">Intiqal Type</label>
@Html.DropDownListFor(model => model.Intiqal.IntiqalTypeId, new SelectList(Model.IntiqalTypes, "IntiqalTypeId", "IntiqalTypeName"), Resources.Select, new { id = "intiqalTypes", Class = "form-control" })
@Html.ValidationMessageFor(model => model.Intiqal.IntiqalTypeId, "", new { id = "", @class = "text-danger" })
</div>
<div class="form-group col-sm-2">
<label class="control-label">Source</label>
@Html.DropDownListFor(model => model.Intiqal.ProcessInitiationTypeId, new SelectList(new List<ProcessInitiationType>
(), "ProcessInitiationTypeId", "ProcessInitiationTypeName"), Resources.Select, new { id = "processInitiationTypes", Class = "form-control" })
@Html.ValidationMessageFor(model => model.Intiqal.ProcessInitiationTypeId, "", new { id = "", @class = "text-danger" })
</div>
<div class="form-group col-sm-2 hidden" id="shamilatSelection">
<label class="control-label">Shamilat</label>
@Html.DropDownListFor(model => model.Intiqal.Shamilat, new SelectList(Model.Shamilat, "Key", "Value"), Resources.Select, new { id = "shamilat", Class = "form-control " })
@Html.ValidationMessageFor(model => model.Intiqal.Shamilat, "", new { @class = "text-danger" })
</div>
</div>
</div>
//Other stuff including submit button
}
什麼問題?
編輯 - 這裏是腳本命令
<script src="/Scripts/jquery-2.2.3.js"></script>
<script src="/Scripts/jquery-ui-1.11.4.min.js"></script>
<script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>
你有'的jQuery .validate.unobtrusive.js'在視圖或佈局? –
是的,我有我的佈局。我查看頁面源代碼。它包括在內。 – CodeLover
最好的猜測是它沒有正確加載,因爲表單在工作時不會提交。它是爲了 - jQuery然後jquery.validate然後jquery.validate.unobtrusive?無論你是否已禁用客戶端驗證 –