【发布时间】:2016-06-11 07:44:00
【问题描述】:
我在 MVC 5 中有一个表单。我的表单上有三个必需的下拉菜单。当我提交表单时,出现错误消息。问题是,当我从下拉列表中选择值时,错误消息仍然显示。然后,如果我提交按钮,所需的错误消息就会消失。
主要问题是立即验证不起作用。当我第一次提交没有选择的表单然后我选择下拉值时,就会发生这种情况。错误仍然显示。 这是我的表格。
@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? -
是的,我的布局中有。我查看页面源。它包括在内。
-
最好的猜测是它没有正确加载,因为如果它正在工作,表单将不会提交。是否按顺序排列 -
jquery然后jquery.validate然后jquery.validate.unobtrusive?你们中的任何一个都禁用了客户端验证 -
@StephenMuecke 我用脚本顺序编辑了问题。请看。
-
看起来不错。您确定没有在视图中包含任何重复项吗?
标签: javascript jquery asp.net-mvc forms