我不断收到此错误消息。
<script src="../../Scripts/jquery-1.8.0.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.23.custom.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#formEmployee").validate({
rules: {
EmployeeModel_Name: "required"
},
messages: {
EmployeeModel_Name: "Please specify your name"
}
})
$("#btnSave").click(function () {
$("#formEmployee").valid();
});
});
@using (Html.BeginForm(null, null, FormMethod.Get, new { name = "formEmployee", id = "formEmployee" }))
{
<fieldset>
<legend>EmployeeModel</legend>
@Html.EditorFor(model => model.EmployeeModel.Name, new { @class = "required" })
<p>
<input id="btnSave" type="button" value="Save" />
</p>
</fieldset>
}
生成的html
<form action="/Dealer/ManageEmployee" id="formEmployee" method="get" name="formEmployee"> <fieldset>
<legend>EmployeeModel</legend>
<div class="editor-label">
<label for="EmployeeModel_Name">Name</label>
</div>
<div class="editor-field">
<input class="text-box single-line" id="EmployeeModel_Name" name="EmployeeModel.Name" type="text" value="">
</div>
<p>
<input id="btnSave" type="button" value="Save">
<input id="btnBack" type="button" value="Back">
</p>
</fieldset>
</form>
答案 0 :(得分:0)
使用Firebug检查您的页面加载,以确保找到并加载链接的JS文件。您在JSFiddle中的代码按预期工作,并附加一个钩子来检查验证是否被调用;
showErrors: function(errorMap, errorList) {
alert("Here!");
}
答案 1 :(得分:0)
有一段时间有两次
$(document).ready(function(){
////bla bla bla
}
在页面中,可能是一个在页眉中,而另一个在页脚中,所以出现此错误,再次检查您的文件...