mvc ajax模态验证没有被调用

时间:2014-12-17 13:24:18

标签: jquery twitter-bootstrap asp.net-mvc-4

我有一个简单的模态形式(mvc / bootstrap / jquery)

在我的头脑中(包括其他内容)

<script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>

表单定义为;

<div class="modal fade" id="send-email">
<div class="modal-header">
    <a class="close" data-dismiss="modal">&times;</a>
    <h3>Email Documents</h3>
</div>
<div class="modal-body">
    @using (Html.BeginForm("Email", "Recommendations", FormMethod.Post, new { id = "emailform" name="emailform"}))
    {
        <input type="hidden" id="enquiryId" name="enquiryId" />
        <span>Email Address:</span><input type="text" id="emailAddress" name="emailAddress" />
        <input type="submit" class="icon-envelope center">
    }
    <div id="validationSummary" class="validation-summary">
        <ul></ul>
    </div>
    <div class="modal-footer">
        <a href="#" class="btn" data-dismiss="modal">Close</a>            
    </div>
</div>

我的验证javascript是;

initArticleModal = function () {
alert('in validate');
$("#emailform").validate({
    rules: {
        emailAddress: { email: true, required: true }
    },
    messages: {
        emailAddress: "Email Address is Required"
    },
    errorContainer: "#validationSummary",
    errorLabelContainer: "#validationSummary ul",
    wrapper: "li",
    submitHandler: function (form) {
        submitSendEmail($(form));                                   
    }
});
}

警报触发,所以我知道我正在初始化它。 但是当我提交时,不会触发submitSendEmail javascript,表单默认为sumbit。也没有验证,所以我认为我的javascript中存在错误,但控制台中没有报告任何内容。

我在某处读到了元素名称,这就是验证的作用。

那我做错了什么?

0 个答案:

没有答案