0

我不断收到此错误消息。

<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>
4

2 回答 2

0

使用 Firebug 检查您的页面加载,以确保您链接的 JS 文件都被找到并加载。您在 JSFiddle 中的代码按预期工作,并带有一个额外的钩子来检查 validate 是否被调用;

showErrors: function(errorMap, errorList) {
                alert("Here!");
              }

http://jsfiddle.net/dABZr/1/

于 2013-06-26T13:15:45.710 回答
0

一段时间有两次

$(document).ready(function(){
////bla bla bla
}

在页面中,可能一个在页眉中,另一个在页脚中,所以出现此错误,请再次检查您的文件...

于 2013-09-23T12:35:36.677 回答