当我使用我的FCK编辑器时,我收到“从客户端检测到可能危险的Request.Form请求值”异常。
如何在提交表单之前进行编码,或者在不禁用Data Anotations验证的情况下禁用此验证?
这是我的观点代码:
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary("Please complete in a right way the fields below.") %>
<fieldset>
<legend>Fields</legend>
<div class="editor-field">
<%: Html.LabelFor(e => e.Name)%>
<%: Html.TextBoxFor(e => e.Name)%>
<%: Html.ValidationMessageFor(e => e.Name)%>
</div>
<div class="editor-field">
<%: Html.LabelFor(e => e.Teaser) %>
<%: Html.TextAreaFor(e => e.Teaser)%>
<%: Html.ValidationMessageFor(e => e.Teaser)%>
</div>
<div class="editor-field">
<%: Html.LabelFor(e => e.Description) %>
<%: Html.TextAreaFor(e => e.Description)%>
<%: Html.ValidationMessageFor(e => e.Description)%>
</div>
<p>
<input type="submit" />
</p>
</fieldset>
<% } %>
<script type="text/javascript">
//<![CDATA[
// This call can be placed at any point after the
// <textarea>, or inside a <head><script> in a
// window.onload event handler.
// Replace the <textarea id="xxxxxx"> with an CKEditor
// instance, using default configurations.
CKEDITOR.replace("Description");
//]]>
</script>
提前多多感谢。
答案 0 :(得分:4)
<httpRuntime requestValidationMode="2.0" />
答案 1 :(得分:3)
[script type =“text / javascript”src =“/ ckeditor / _source / core / editor.js”] [/ script]
CKEDITOR.config.htmlEncodeOutput = true;
答案 2 :(得分:2)
如果您正在使用FCK编辑器或CKeditor,则无需处理&#34; requestValidationMode&#34;。因为它将应用于整个应用程序。 您可以执行以下操作:
CKEDITOR.replace('Description', { toolbar: '1', htmlEncodeOutput: true});
然后在控制器中:
model.Body = System.Net.WebUtility.HtmlDecode(model.Body);
答案 3 :(得分:0)