Feb 20, 2015, 10:22 AM
[CLOSED] fileuploadfield not working when using direct method request
I am using FileUploadField to upload a file onto server like:
view code for fileuploadfield
And, when I use DirectEvents instead of DirectMethod it works fine. Why is it like that?
view code for fileuploadfield
X.FileUploadField().ID("myUploadField").ButtonOnly(true).Icon(Icon.Attach).ButtonText("Export my excel")
.Listeners(l => { l.Change.Handler = "jsExport2Excel();"; })
//.DirectEvents(de =>
//{
// de.Change.Url = Url.Action("ExportExcel", "Report");
// de.Change.IsUpload = true;
//})
js codevar jsExport2Excel = function () {
Ext.net.DirectMethod.request({
url: "/Report/ExportExcel",
cleanRequest: true,
isUpload: true
});
}
controller action code[DirectMethod]
public ActionResult ExportExcel()
{
FileUploadField fileUploadField = X.GetCmp<FileUploadField>("myUploadField");
HttpPostedFile file = fileUploadField.PostedFile;
if (fileUploadField.HasFile)
{
string filePath = file.FileName;
//string path = this.HttpContext.Server.MapPath("~") + "\\" + fileName;
string dateInWordFormat = GetDateInSpecificFormat();
string tmpFilePath = Constants.ExcelDetails.DefaultSavePath + Constants.ExcelDetails.DefaultFileName + ".xlsx";
string finalFilePath = Server.MapPath(tmpFilePath);
file.SaveAs(finalFilePath);
}
else
{
X.Msg.Show(new MessageBoxConfig
{
Buttons = MessageBox.Button.OK,
Icon = MessageBox.Icon.ERROR,
Title = "Fail",
Message = "No file uploaded"
});
}
DirectResult result = new DirectResult();
result.IsUpload = true;
return result;
}
FileUploadField.HasFiles is always coming false. And, when I use DirectEvents instead of DirectMethod it works fine. Why is it like that?
Last edited by Daniil; Mar 03, 2015 at 9:56 AM.
Reason: [CLOSED]