Mar 02, 2015, 7:41 AM
[CLOSED] DirectMethod problem
View code:
But, it's not happening that way, when user uploads empty excel file then the exception thrown in the controller action method does not goes back to javascripts error function and rather just shows the bad response error window to the user and also gives an option to open uploaded file in the json format with the direct methods name as the filename.
Can anybody guide me what's wrong I am doing here?
Thanks
@model System.Collections.IEnumerable
@{
ViewBag.Title = "My Report";
var X = Html.X();
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title></title>
<script type="text/javascript">
var jsExport2Excel = function () {
Ext.net.DirectMethod.request({
url: "/Report/ProduceEEReportWithDirectorInformation",
cleanRequest: true,
isUpload: true,
formId: "myForm",
success: function (result) {
Ext.Msg.Show("Excel file export successfull");
},
error: function (result) {
Ext.Msg.Show("Export unsuccessfull");
}
});
};
</script>
</head>
<body>
@section sectionCenterBody
{
}
@section OptionalContent
{
<script src="~/Scripts/Report/EEReport.js"></script>
<div>
<form id="myForm">
<div align="center" style="Position:relative; top: 200px">
@(X.FileUploadField().ID("myUploadField").ButtonOnly(true).Icon(Icon.Attach).ButtonText("Produce EE Report With Director Information")
.Listeners(l => l.Change.Fn = "jsExport2Excel"))
</div>
</form>
</div>
}
</body>
</html>
Controller 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);
ReadSavedExcel();
WriteNewExcelAndOpen();
}
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;
}
Above code runs fine if user does everything as required, but if user uploads empty excel file then I want my JavaScripts DirectMethod's error function to be called upon and gives a message to user "Export Unsuccessfull". But, it's not happening that way, when user uploads empty excel file then the exception thrown in the controller action method does not goes back to javascripts error function and rather just shows the bad response error window to the user and also gives an option to open uploaded file in the json format with the direct methods name as the filename.
Can anybody guide me what's wrong I am doing here?
Thanks
Last edited by Daniil; Mar 06, 2015 at 5:30 AM.
Reason: [CLOSED]