Skip to content

Issue with File Upload and Record Update Post Request in the JSGrid #1443

@wareworks

Description

@wareworks

Sharing Update Snippet where we are uploading the file while editing the record with all the options in the commented more which we tried. All other options are working fine.

updateItem: function (item) {

//// Set the default method to "post" if not specified
// var method = "POST";
// //var path = "/api/UpdateRequest";
// var path = "/manage/detail/UpdateRequest/@Model.Case.Id";

// // Create a new form element
// var form = document.createElement("form");

// // Set the method and action attributes of the form
// form.setAttribute("id", 'FormUpdateDiagnosticRequest');
// form.setAttribute("method", method);
// form.setAttribute("action", path);
// form.setAttribute("enctype", "multipart/form-data");

// var verificationField = document.createElement("input");
// // Set the type, name, and value attributes of the hidden input field
// verificationField.setAttribute("type", "hidden");
// verificationField.setAttribute("name", "__RequestVerificationToken");
// verificationField.setAttribute("value", $('input:hidden[name="__RequestVerificationToken"]').val());
// form.appendChild(verificationField);

// // Create a new hidden input field for each key-value pair
// var hiddenField = document.createElement("input");
// // Set the type, name, and value attributes of the hidden input field
// hiddenField.setAttribute("type", "hidden");
// hiddenField.setAttribute("name", "Request");
// hiddenField.setAttribute("value", JSON.stringify(item));

// //Append the hidden input field to the form
// form.appendChild(hiddenField);

// // Create a new hidden input field for each key-value pair
// var fileField = document.createElement("input");
// // Set the type, name, and value attributes of the hidden input field
// fileField.setAttribute("type", "file");
// fileField.setAttribute("multiple", "");
// fileField.setAttribute("style", "display:none");
// fileField.setAttribute("name", "PostedFiles");
// form.appendChild(fileField);

// var verField = document.createElement("input");
// // Set the type, name, and value attributes of the hidden input field
// verField.setAttribute("type", "hidden");
// verField.setAttribute("name", "__RequestVerificationToken");
// verField.setAttribute("value", $('input:hidden[name="__RequestVerificationToken"]').val());
// form.appendChild(verField);

//console.log(item);

// item.data.testReportsFiles.then((resolvedArray) => {
// // Assigning it to another variable
// const newArray = resolvedArray;
// //console.log(newArray);
// fileField.setAttribute("value", newArray);
// formData.append("PostedFiles", newArray);
// });

// console.log(formData);

// //Append the form to the document body
// document.body.appendChild(form);

// form.submit();

// //item.data.testReportsFiles = newArray;
// console.log('UpdateItem');
// item.newStatus = "Published";
//console.log(item);

   //var formData = new FormData();
   //formData.append("Request", JSON.stringify(item));
   //formData.append("__RequestVerificationToken", $('input:hidden[name="__RequestVerificationToken"]').val());

   return $.ajax({
    type: "POST",
        url: "/manage/detail/UpdateRequest/" + item.id,
    headers: {
            "RequestVerificationToken": $('input:hidden[name="__RequestVerificationToken"]').val()
    },
    data: item,
    success: function (data) {
        $("#diagnostic-tests-table").jsGrid("loadData");
    },
    error: function (jqXHR, textStatus, error) {
        alert("Some error occurred while updating the patient. Please try again.");
    }
});

}
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions