Kendo Upload widget and MVC
How do you save an uploaded file using a Kendo Upload widget?
Important Notes:
1. Don't use kendo's sample name for the control which is photos[] . Just use photos or anyname without the array symbol [].
2. Use IEnumerable<HttpPostedFileBase> as a parameter in your controller, and make sure the parameter name is same as the control name, in our case it's photos.
The API from Kendo uses a sample that sets the name of the input control to photos[] . You need to override this to just photos for processing in the Controller.
@using (Html.BeginForm()) {
<div>
<input name="photos[]" id="photos" type="file" />
</div>
}
View
<input name="photos" id="photos" type="file" />
Controller
[HttpPost] public ActionResult UploadForm(int id, FormCollection collection, IEnumerable<HttpPostedFileBase> photos) {
foreach (var file in photos) { //check for null. kendos control uploads an empty input file by default if (file == null) continue; //check for content if (file.ContentLength == 0) continue; // Some browsers send file names with full path. This needs to be stripped. var fileName = Path.GetFileName(file.FileName); var physicalPath = Path.Combine(Server.MapPath("~/Uploads"), fileName); file.SaveAs(physicalPath);
}
}










