I am using the upload in multiple places, but usually only passing one or two integers along with the uploaded document, and that works.
On this new page I am building, I need to upload the document, but with over 20 fields, and a couple collections of records.
Normally we will create an object, and JSON.stringify it to pass it to the Controller, like this...
Javascript
Controller
This all works, but when I try to do the same thing when uploading a file, I get a null object...
Javascript
Controller
When I get to the controller, my object is null.
Is there a way to pass an object like this through the upload?
On this new page I am building, I need to upload the document, but with over 20 fields, and a couple collections of records.
Normally we will create an object, and JSON.stringify it to pass it to the Controller, like this...
Javascript
var obj = {};obj.ID = 1;obj.Name = "Joe";var DTO = { 'DTO': obj };$.ajax({ type: "POST", contentType: 'application/json;charset=utf-8', url: "/Controller/Method", dataType: "json", data: JSON.stringify(DTO), success: function (data) { // do stuff }, complete: function () { // do stuff }});public JsonResult Method(SomeClass DTO){ // do stuff}Javascript
$("#contractUpload").kendoUpload({ multiple: false, showFileList: false, localization: { select: GetUploadSelectText(), dropFilesHere: "Drop File Here" }, async: { saveUrl: '/Contract/UploadFile', autoUpload: true }, select: function (e) { // check file types }, upload: function (e) { // get values from page into a DTO var SaveContract = {}; SaveContract.bdID = $("#hidBDID").val(); SaveContract.DocumentType = $("#hidContractType").val(); //billing terms var billingTermsViewModel = {}; billingTermsViewModel.ContractID = window.billingTermsModel.ContractID; //save deleted rows var removedBillingTerms = []; $.each(window.removedBillingTerms.data(), function (index, value) { var removedBillingTermsItem = {}; removedBillingTermsItem = value.ID; removedBillingTerms.push(removedBillingTermsItem); }); billingTermsViewModel.RemovedBillingTerms = removedBillingTerms; //look through any rows that have been updated and send the updates to the view model var directBillingTerms = []; $.each(window.dataSourceDirectBillingTerms.data(), function (index, value) { if (value.dirty == true || value.ID == 0) { var directBillingTermsItem = {}; var stipulatedTermItem = {}; directBillingTermsItem.ID = value.ID; directBillingTerms.push(directBillingTermsItem); value.dirty = false; } }); var indirectBillingTerms = []; $.each(window.dataSourceIndirectBillingTerms.data(), function (index, value) { if (value.dirty == true || value.ID == 0) { var indirectBillingTermsItem = {}; var stipulatedTermItem = {}; indirectBillingTermsItem.ID = value.ID; indirectBillingTerms.push(indirectBillingTermsItem); value.dirty = false; } }); billingTermsViewModel.RemovedBillingTerms = removedBillingTerms; billingTermsViewModel.DirectBillingTerms = directBillingTerms; billingTermsViewModel.IndirectBillingTerms = indirectBillingTerms; SaveContract.BillingTermsViewModel = billingTermsViewModel; var DTO = { 'DTO': SaveContract }; e.data = { doc: e.files[0].rawFile, DTO: JSON.stringify(DTO) }; }, success: function(data) { //do stuff }, error: function (e) { //do stuff }});[HttpPost]public ActionResult UploadFile(IEnumerable<HttpPostedFileBase> files, HttpPostedFileBase doc, SaveContract DTO) { // when i get here, DTO is null}When I get to the controller, my object is null.
Is there a way to pass an object like this through the upload?