I know how to upload attachment to list item through JavaScript or with C#. But I am having different scenario here. I am uploading attachment using HTML file upload control. Now I want to send this uploaded file information to C# method (MVC). I am using $.post() method. I am not getting file content at all to controller method. I am sending file data as reader.readAsArrayBuffer(f). Below is my code to read file data

function handleFileSelect(evt){
    var files = evt.target.files; // FileList object    
    var formdata = new FormData(); //FormData object
    for (var i = 0, f; (f = files[i]); i++) {
        var reader = new FileReader();      
        reader.onload = ((theFile) => {
            return (e) => {             
                let _files = attachmentsCollections;
                    AttachmentName: theFile.name,
                    Content: e.target.result,
                    Type: "New",

Below method to send data to controller:

let teamToCreate = { TeamName: newTeamName, Attachments: attachmentsCollections };
$.post(actionUrl, teamToCreate, function (data) {});

But in controller, I am getting Content as null. Any thoughts on this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.