skip to Main Content

I have an ajax call that is not executing how I would expect. I am receiving an error from the browser of “jquery-1.10.2.js:8157 Uncaught TypeError: Cannot read property ‘FileGuid’ of undefined”. I have break points in my CS file at the start of both the GetExportData and Download functions but neither one of them are ever hit.

function generateExportFile() {
        var datefrom = $('#tab_MHSubpay_datefrom').ejDatePicker("getValue");
        var dateto = $('#tab_MHSubpay_dateto').ejDatePicker("getValue");
        var show = $('#tab_MHSubpay_show').ejDropDownList("getSelectedValue");
        var service = $('#tab_MHSubpay_serviceType').ejDropDownList("getSelectedValue");
        var phase = $('#tab_MHSubpay_phaseCode').ejDropDownList("getSelectedValue");


        $('#accwpopup').ejWaitingPopup({
            showOnInit: true,
            text: "Generating file...",
            target: "#tbldata"
        });

        debugger;
        $.ajax({
            cache: false,
            url: '@Url.Action("GetExportData", "MHSubpay")',
            data: {
                datefrom: datefrom,
                dateto: dateto,
                show: show,
                service: service,
                phase: phase
            },
            success: function (data) {
                $('#accwpopup').ejWaitingPopup('destroy');
                window.location = '@Url.Action("Download", "MHSubpay")?fileGuid=' + data.Data.FileGuid + '&filename=' + data.Data.FileName;
            },
            error: function (data) {
                $('#accwpopup').ejWaitingPopup('destroy');
                showMessage("An error ocurred trying to generate the file", false);
            },
            async: false
        });
    }

2

Answers


  1. Chosen as BEST ANSWER

    It turns out this was a really dumb mistake that I just kept glossing over. I never updated the server side code, which I recycled from another controller, to be an HttpGet function rather than an HttpPost. Once I switched that the call went through properly.


  2. The affected line is this, because this is the only line where you try to access the FileGuid property:

    window.location = '@Url.Action("Download", "MHSubpay")?fileGuid=' + data.Data.FileGuid + '&filename=' + data.Data.FileName;
    

    More specifically this part of the line:

    data.Data.FileGuid
    

    Based on that the Ajax request executes successfully, but the response doesn’t have a Data propery.

    What I’d do is I’d put a console.log(data) at the first line of the success method to see what’s in the response body.

    Sidenote: this is JavaScript code which runs in the browser, so it doesn’t make much sense to put breakpoints in this CS file which runs on the server side.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search