[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>
        <meta name="viewport" content="width=device-width" />
        <script type="text/javascript">
            var jsExport2Excel = function () {
                    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");
        @section sectionCenterBody
        @section  OptionalContent
        <script src="~/Scripts/Report/EEReport.js"></script>
            <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"))
    Controller Code:
    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);
                    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?

    Last edited by Daniil; Mar 06, 2015 at 5:30 AM. Reason: [CLOSED]

Similar Threads

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

Tags for this Thread

Posting Permissions