{"$id":"1","success":true,"result":"Uploaded Successfully.","error":null}
问题是上传没有完成。它一直在显示"请等待......"信息。查看Chrome开发人员工具,我收到错误消息:"未捕获TypeError:undefined不是函数"
以下是该视图的完整代码:
Ext.define('MyApp.view.AddCountry', {
extend: 'Ext.window.Window',
alias: 'widget.addcountry',
closable: true,
closeAction: 'destroy',
modal: true,
height: '28%',
width: '45%',
layout: 'fit',
initComponent: function () {
var me = this;
me.items = [{
xtype: 'form',
bodyPadding: '5 5 0',
itemId: 'addCountryForm',
frame: false,
headers: { 'Content-Type': 'text/html' },//Removing this also doesn't work.
items: [{
xtype: 'textfield',
fieldLabel: 'Name',
maxLength: 25,
enforceMaxLength: true,
allowBlank: false,
flex: 1
}, {
xtype: 'textfield',
fieldLabel: 'Description',
maxLength: 100,
enforceMaxLength: true,
allowBlank: false,
flex: 1
}, {
xtype: 'filefield',
name: 'flagImage',
fieldLabel: 'Flag',
buttonText: 'Select Image...',
flex: 1
}],
buttons: [{
text: 'Save',
itemId: 'btnAddCountry'
}, {
text: 'Cancel',
itemId: 'btnCancelAddingCountry'
}]
}];
this.callParent();
}
});
控制器代码:
AddNewCountry: function (button) {
var form = button.up('form').getForm();
form.submit({
url: 'localhost/myapp/api/addcountry',
waitMsg: 'Please wait...',
success: function (f, o) {
Ext.Msg.alert('Success', o.result.result);
},
failure: function (f, o) {
Ext.Msg.alert('Error', o.result.error);
}
});
},
这是我在服务器端编写的内容:
public UploadResult AddNewCountry()
{
var httpRequest = HttpContext.Current.Request;
if (httpRequest.Files.Count > 0)
{
string fileName = httpRequest.Files[0].FileName;//I am able to get this
}
UploadResult objResult = new UploadResult();
objResult.success = true;
objResult.result = "Uploaded Successfully.";
return objResult;
}
public class UploadResult
{
public bool success { get; set; }
public string result { get; set; }
public string error { get; set; }
}
我确信在Form配置中必须有一些东西,但我无法找到。有人可以在这里指出这个问题吗?