Hi,
Is it possible to
send a model object/complex object and not just simple primitives
as data object of upload event of KendoUpload and access the same in controller's action method? I always get null value on controller action if i try sending any object with multiple properties.
Is this a bug/shortcoming of Kendo Upload control? Please let me know if you have a solution for the same.
As long as I send simple entries like multiple strings etc., each one of them is accessible on the controller action. But when I try to send a complex object like the model as a whole or creating JSON string, I only get null value for object on the controller action method.
I have to send a good number of fields to associate with the file as its metadata information. So, it will be cleaner for me if I could send the whole model object as additional data to async upload control and subsequently access the same in the controller action handling file save operation.
I am using MVC3 with Razor, C#. Following is my brief code structure, for reference:
Controller Action and
Model class :
[HttpPost]
public ActionResult UploadFile(IEnumerable<
HttpPostedFileBase
> files, AzureUploaderModel uploader)
{
//Removing internal code for brevity. I should be able to get a data filled 'uploader' at this point and not null.
// Return an empty string to signify success
return Content("");
}
public class AzureUploaderModel
{
public string AzureAccountName { get; set; }
public string AzureAccountKey { get; set; }
public string ContainerName { get; set; }
public String ContainerFilterId { get; set; }
}
View code:
<input name="files" id="upload" type="file"/>
$("#upload").kendoUpload({
template: kendo.template($('#fileTemplate').html()),
async: {
saveUrl: '@Url.Action("UploadFile", "AzureUpload")',
removeUrl: '@Url.Action("Remove", "AzureUpload")',
autoUpload: false
},
upload: onUpload
});
ONUPLOAD -try1
function onUpload(e) {
e.data = { uploader: '@Model'}; }
ONUPLOAD -try2
function onUpload(e) {
var uploader = {
AzureAccountName: $("#AzureAccountName").val(),
AzureAccountKey: $("#AzureAccountKey").val(),
ContainerName: $("#ContainerName").val()
};
// var postData = JSON.stringify(uploader);
e.data = { uploader: uploader}; //postData };
}