【问题标题】:Returning a form using ajax/jquery that includes html within an input使用在输入中包含 html 的 ajax/jquery 返回表单
【发布时间】:2014-08-15 12:02:27
【问题描述】:

所以,我试图返回一个隐藏字段(它是表单提交的一部分),其中包含一串 html 格式的文本,这是有原因的,html 正在内部呈现为 pdf。我目前正在使用 ajax 将表单发回。表单会序列化,但当表单包含 html 字符串时,会在尝试查找控制器时返回 500 错误。

代码:

 $(function () {
            $('#preview').click(function (evt) {
                //prevent the browsers default function
                evt.preventDefault();
                var $form = $('#sform');
                $.ajax({
                    type: $form.prop('method'),
                    url: $form.prop('action'),
                    data: $form.serialize(),
                    dataType: "json",
                    traditional: true,
                    success: function (response) {
                        var newURL = window.location.protocol + "//" + window.location.host + "//" + response;
                        document.getElementById('myIframe').src = newURL;
                    }
                });
            });
        });

【问题讨论】:

    标签: ajax json model-view-controller jscript


    【解决方案1】:

    您可能需要关闭请求验证。您可以使用

    标记您的控制器方法
    [ValidateInput(false)]
    

    哦,我认为对于更高版本的 MVC,您还需要

    <system.web>
        <httpRuntime requestValidationMode="2.0"/>
        ...
    </system.web>
    

    【讨论】:

      猜你喜欢
      • 2011-08-01
      • 2014-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-01
      • 1970-01-01
      • 2020-06-02
      相关资源
      最近更新 更多