C# 带有fileuploadfield的Ext表单(提交后的响应)
我真的不明白哪里出了错 我有一个带有fileuploadfield的表单。请求发送良好,控制器上的操作获取所有参数,使用它们,并将响应发送到浏览器。但在html页面中,提交表单后,总是触发失败事件,而从不成功 客户端代码C# 带有fileuploadfield的Ext表单(提交后的响应),c#,asp.net-mvc,extjs,C#,Asp.net Mvc,Extjs,我真的不明白哪里出了错 我有一个带有fileuploadfield的表单。请求发送良好,控制器上的操作获取所有参数,使用它们,并将响应发送到浏览器。但在html页面中,提交表单后,总是触发失败事件,而从不成功 客户端代码 Ext.create('Ext.form.Panel', { renderTo: 'Container', bodyPadding: '10 10 0', items: [ { xtype:
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}
在使用表单后,我需要在代码中修复什么才能获得成功事件?您调用了两次
Json
方法。你唯一需要的是
public JsonResult UploadFile(HttpPostedFileWrapper file, int id)
{
return Json(new { success = true });
}
谢谢你,亚历克赛!))(你的帮助非常有用)