[CLOSED] DirectMethod problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    [CLOSED] DirectMethod problem

    View code:

    @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 6:30 AM. Reason: [CLOSED]

Similar Threads

  1. [CLOSED] DirectMethod's problem
    By softmachine2011 in forum 2.x Premium Help
    Replies: 1
    Last Post: Jun 06, 2012, 4:56 PM
  2. DirectMethod problem
    By abhijit in forum 1.x Help
    Replies: 4
    Last Post: Dec 23, 2011, 1:43 PM
  3. [CLOSED] DirectMethod with UserControl Problem
    By nhg_itd in forum 1.x Premium Help
    Replies: 1
    Last Post: Sep 21, 2011, 9:00 AM
  4. [CLOSED] DirectMethod.Request Problem
    By tansu in forum 1.x Premium Help
    Replies: 10
    Last Post: Oct 28, 2010, 9:18 AM
  5. Replies: 2
    Last Post: Oct 08, 2010, 8:09 PM

Tags for this Thread

Posting Permissions