views:

191

answers:

1

I am using a jQuery Ajax control from this site http://abeautifulsite.net/2008/03/jquery-file-tree/

I have it all working. I tried to ask a support question but never heard back, thinking maybe someone on here can shed some light on the situation.

Basically what I am trying to do, is on a file selection run an action that returns a JsonResult, that gives more details about the file and then show them to the screen in a container. While I debug, the method gets hit, returns the correct data. After the return in the ajax call i get a error in firebug say the recursionlimit exceeded. I am not sure how to get around this...I thought I could use the callback of the fileTree(options, callback) method provided but that is not fired on selection of the file only the initialization of the file tree. Any ideas?

Heres what I did via JavaScript

function initFileTree() {

    $('#fileTree').fileTree({ root: '/', script: '/Scripts/filetree/jqueryFileTree.aspx', multiFolder: false, expandEasing: 'easeOutBounce', collapseEasing: 'easeOutBounce' }, function(file) {

        getFileDetails(file);

    });

}

function getFileDetails(file) {

    // alert(file);

    $.getJSON('/Files.mvc/GetFileDetails', { Data: file }, function(data) {
        $('#fileDetail').html('<h6>Selected File: ' + data.Length + '</h6>');
    }, 'json');
}

Here is my action that take the data and returns a JsonResult

public virtual JsonResult GetFileDetails(string data)
        {
            string pageMessage = null;

            FileInfo fileInfo = null;

            try
            {
                fileInfo = new FileInfo(data);
            }
            catch (Exception e)
            {
                pageMessage = e.Message;    
            }

            return Json(fileInfo);
        }
+2  A: 

Apparently returning a FileInfo obj is not acceptable for a JsonResult. Simplifying the return, I changed it to:

return Json("helloWorld");

and all my problems went away. Not sure why it cares that I was attempting to return a FileInfo type but either way problem solved when I changed it to return a string. So now I just create a small wrapper class to hold the data I want to pass back and life is good.

Thanks! Hope this helps someone else.

gmcalab
be sure to accept your own answer too ...
Jason D