いてづきブログ

情シスでやってみたことの備忘録

Extjsのファイルアップロード

{
xtype: 'form',
width: 400,
height: 350,
layout: 'vbox',
items: [{
// トークン
xtype: 'hidden',
name: '__RequestVerificationToken'
}, {
xtype: 'filefield',
name: 'file',
width: 400,
hideLabel: true,
buttonText: "アップロード",
msgTarget: 'side',
buttonOnly: true,
listeners: {
'change' : function (a, b, c){
var form = this.up('form').getForm();

if(form.isValid()){

// トークン設定
var token = $('[name=__RequestVerificationToken]').val();
form.findField('__RequestVerificationToken').setValue(token);

form.submit({
url : http://localhost/Upload,
waitMsg : 'アップロードしています...',
scope:this,
success: function(){
alert('success');
},
failure: function (basicForm, action) {
Ext.Msg.alert('エラー', 'サーバーへの接続に失敗しました。').setIcon(Ext.Msg.ERROR);
}
});
}
}
}
}],

}

サーバー側

public ActionResult Upload(HttpPostedFileBase file)
{

// 処理

return Content("success");
}


取り急ぎメモ。
filefieldのnameと、サーバー側の引数の名前を一致させる必要がある。