MVC客户端验证导致错误

时间:2010-07-29 04:47:39

标签: asp.net-mvc validation ckeditor data-annotations

我希望有人遇到过类似的事情。带有文本的文本输入会触发客户端[必需]错误消息。

我在主人中有以下内容:

<script src="/Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="/Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcAjax.debug.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.js" type="text/javascript"></script>

以及

<% Html.EnableClientValidation(); %>

在视图中。

有几个可能的因素:

  • 表格处于局部视图
  • 提交的文本来自CKEditor
  • 隐藏了CKEditor 在页面加载,然后通过显示 jQuery的

我只是不确定是什么原因引起的。

形式:

<form action="/Quote/Create/1" id="form0" method="post"><div class="validation-summary-valid" id="validationSummary"><ul><li style="display:none"></li>

</ul></div>
<fieldset>
    <legend>Fields</legend>
    <div class="editor-field">
        <input id="QuoteID" name="QuoteID" type="hidden" value="0" />
    </div>
    <div class="editor-field">
        <input id="UserID" name="UserID" type="hidden" value="54cb0fde-649d-429c-8800-6bd9cc286d90" />
    </div>

        <div class="editor-label">
        <label for="PageNumber">PageNumber</label>
    </div>
    <div class="editor-field">
        <input id="PageNumber" name="PageNumber" type="text" value="" />
        <span class="field-validation-valid" id="PageNumber_validationMessage"></span>
    </div>
    <div class="editor-label">

        <label for="QuoteText">QuoteText</label>
    </div>
    <div class="editor-field">
        <textarea cols="20" id="QuoteText" name="QuoteText" rows="2">
</textarea>
        <span class="field-validation-valid" id="QuoteText_validationMessage"></span>
    </div>
    <div class="editor-field">
        <input id="BookID" name="BookID" type="hidden" value="1" />

    </div>
    <div class="editor-field">
        <input id="DateCreated" name="DateCreated" type="hidden" value="7/28/2010 9:21:36 PM" />
    </div>
    <p>
        <input id="quoteSubmit" type="submit" value="Create" />
    </p>
</fieldset>
</form><script type="text/javascript">
//<![CDATA[
if (!window.mvcClientValidationMetadata) { window.mvcClientValidationMetadata = []; }
window.mvcClientValidationMetadata.push({"Fields":[{"FieldName":"PageNumber","ReplaceValidationMessageContents":true,"ValidationMessageId":"PageNumber_validationMessage","ValidationRules":[{"ErrorMessage":"The field PageNumber must be a number.","ValidationParameters":{},"ValidationType":"number"}]},{"FieldName":"QuoteText","ReplaceValidationMessageContents":true,"ValidationMessageId":"QuoteText_validationMessage","ValidationRules":[{"ErrorMessage":"That quote is too long.","ValidationParameters":{"minimumLength":0,"maximumLength":500},"ValidationType":"stringLength"},{"ErrorMessage":"You didn\u0027t even enter a quote...","ValidationParameters":{},"ValidationType":"required"}]}],"FormId":"form0","ReplaceValidationSummary":false,"ValidationSummaryId":"validationSummary"});
//]]>
</script>

当我拿出

<% Html.EnableClientValidation(); %>

服务器端验证工作正常,不会产生错误。

1 个答案:

答案 0 :(得分:1)

我明白了!

$('#quoteSubmit')。click(function(){     CKEDITOR.instances [ 'QuoteText'] updateElement(); });

Yeehaw。