0

真的不明白哪里错了。。

我有一个带有文件上传字段的表单。请求发送良好,我的控制器上的操作获取所有参数,使用它们,并向浏览器发送响应。但是在html页面中,提交表单后,总是触发FAILURE事件,并且永远不会成功。

客户端代码

Ext.create('Ext.form.Panel', {
        renderTo: 'Container',
        bodyPadding: '10 10 0',
        items: [
        {
            xtype: 'form',
            width: 300,
            border: false,
            fileUpload: true,
            items: [
            {
                xtype: 'combobox',
                id: 'PayTypes',
                width: 215,
                store: PayTypesStore,
                valueField: 'id',
                displayField: 'Name',
                editable: false,
                name: 'id'
            }
            ,
            {
                xtype: 'filefield',
                id: 'form-file',
                name: 'file',
                buttonText: '',
                buttonConfig: {
                    iconCls: 'upload-icon'
                }
            }
            ],
            buttons: [
            {
                text: 'Send',
                handler: function () {
                    var form = this.up('form').getForm();
                    if (form.isValid()) {
                        form.submit({
                            url: 'UploadFile',
                            waitMsg: 'Uploading your photo...',
                            success: function (fp, o) {
                                console.log("success");
                                msg('Success', 'Processed file on the server');
                            },
                            failure: function (form, action) {
                                console.log(action);
                                Ext.Msg.alert('Failed', action.result ? action.result.message : 'No response');
                            }
                        });
                    }
                }
            }
            ]
        }
        ]
    });

服务器端代码:

public JsonResult UploadFile(HttpPostedFileWrapper file, int id)
    {
        var response = Json(new { success = true });
        response.ContentType = "text/html";

        return Json(response);
    }

响应,在客户端收到:

{"ContentEncoding":null,"ContentType":"text/html","Data":"success":true},"JsonRequestBehavior":1,"MaxJsonLength":null,"RecursionLimit":null}

我需要在我的代码中修复什么以在 sumniting 表单后获得 SUCCESS 事件?

4

1 回答 1

0

你调用Json了两次方法。你唯一需要的是

public JsonResult UploadFile(HttpPostedFileWrapper file, int id)
{
    return Json(new { success = true });
}
于 2012-11-06T08:47:27.260 回答