Search code examples
c#jqueryjsonmodel-view-controllerkendo-upload

Access Json collection returned from Kendo Upload Complete function


Wrapping my head around this for the last two hours and I cannot seem to figure it out. All I'm trying to do is access a collection in a response from a Controller that is sent via the Kendo Uploader.

Any help, Greatly appreciated!

The code:

$("...").kendoUpload({
            async: {
                saveUrl: "...",
                removeUrl: "...",
                autoUpload: true
            },
            complete: function (e) {
                onKendoDocSuccess(e, '@Model.FieldValue.Id');

                $.each(e.response, function (index, value) {
                    alert(value.FileName);
                    var html = "<div class='fieldvaluedocument' data-fieldvalueid='@Model.FieldValue.Id'> " +
                                    "<a href='#' title=''>" + value.FileName + "(" + value.SizeInKb + "Kb)</a>&nbsp;&nbsp;" +
                               "</div>";

                    $('.js-list-files').prepend(html);
                });
            },

The return in the controller:

return Json(new { uploadedContent = uploadedFile}, "text/plain");

uploadedContent is a collection.

enter image description here

Iv'e tried numerous ways to try and access the collection in JavaScript but either I get undefined, Token not recognized etc.

Iv'e never had this much trouble before, I must be missing the obvious.

Appreciate your time.

Regards,


Solution

  • Try to parse Json, then you can access collection, etc.

    var obj = $.parseJSON(json);