ASP.NET MVC中的Dropzone错误消息

3

使用ASP.NET MVC,在提交的应用/表单缺少某些内容时,我会返回错误。在放置文件的投放区域上出现漂亮的红色"X",但错误消息是"[object Object]"

我的控制器:

        if (some error)
        {
            Response.ClearHeaders();
            Response.ClearContent();
            Response.StatusCode = 500;
            Response.StatusDescription = "Internal Error";
            return Json(new { Message = "Missing Something", JsonRequestBehavior.AllowGet });
        }

我的Javascript:

<script>
    //File Upload response from the server
    Dropzone.options.dropzoneForm = {
        maxFilesize: 20,
        init: function() {
            this.on("complete", function(data) {
              // ???????  var res =  data.xhr.responseText ;
            });
        }
    };
</script>
1个回答

1
这是我的解决方案。
<script>
    //File Upload response from the server
    Dropzone.options.dropzoneForm = {
        maxFilesize: 20,
        init: function() {
            this.on("error", function(data, errorMessage, xhr) {
                $(".alertError").show();
                $(".alertSuccess").hide();
                $(".errMessage").text(errorMessage.Message);
            });

            this.on("processing", function(data) {
                $(".alertError").hide();
                $(".alertSuccess").hide();
            });


            this.on("success", function (data) {
                $(".alertError").hide();
                $(".alertSuccess").show();
            });
        }
    };
</script>

现在我可以使用红色 X 了,但是我仍然收到 [object Object] 的消息,你改变了返回的 JSON 吗? - SGP

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接