Hello,
I used kendo upload widget in my project MVC project. How to pass the files through ajax to MVC method without submitting the form? I tried couple of ways but failed to get the files. Could someone help? Please see my sample code below:
---------In .cshtml file -----------
<div >
@(Html.Kendo().Upload()
.Name("files")
.Multiple(false)
.HtmlAttributes(new { aria_label = "files" })
.Validation(validation => validation.AllowedExtensions(new string[] {".xlsx" }))
)
@(Html.Kendo().Button()
.Name("UploadFile")
.Content("Process Files")
.Events(event => event.Click("onUploadFile "))
)
</div>
------In . js file:-------
Function onUploadFile(){
var upload = $("#files").data("kendoUpload"),
files = upload.getFiles();
$.post("TestMethod" ,
{ files: files }, <-----------------------------------I try to pass parameter here.
function (data, status) {...}
);
}
------In server side:-------
public JsonResult TestMethod (IEnumerable<HttpPostedFileBase> files)
{ ....
return Json(null, JsonRequestBehavior.AllowGet);
}