MVC 客户端验证导致错误
我希望有人遇到过类似的事情。 带有文本的文本输入触发客户端[必需]错误消息。
我在 master 中包含以下内容:
<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(); %>
在 view 中包含以下内容。
几个可能的因素:
- 表单处于部分视图中
- 提交的文本来自 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(); %>
服务器端验证时,它工作正常并且不会产生错误。
I'm hoping someone has run into something similar. A text input with text is triggering the client-side [Required] error message.
I have the following included in the master:
<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>
as well as having
<% Html.EnableClientValidation(); %>
in the view.
A couple possible factors:
- The form is in a partial view
- The submitted text is coming from CKEditor
- The CKEditor is hidden
on page load and then revealed via
jQuery
I'm just not sure what could be causing this.
Form:
<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>
When I take out the
<% Html.EnableClientValidation(); %>
server-side validation works fine and generates no error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了!
$('#quoteSubmit').click(function () {
CKEDITOR.instances['QuoteText'].updateElement();
});
哎哟。
I figured it out!
$('#quoteSubmit').click(function () {
CKEDITOR.instances['QuoteText'].updateElement();
});
Yeehaw.