我在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?无论你是否已禁用客户端验证 –