I have an Upload control that works fine, except I want to show the user if their file was accepted or not. I've followed the Documentation example to show the alert message, but I don't want an alert popup - I want to display the message next to the file in the same way that the Cancel/Uploading buttons appear in the example, and the check mark appears. However, I'm extremely new to jQuery and don't understand how to go about that. It also doesn't make sense to me that no matter what I send, it is regarded as a success...
View:
Controller:
View:
@model Datamart.Models.FileSpec@{ ViewBag.Title = "Upload Datamart File";}<h2>Upload Excel File</h2><script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script><script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>File must be less than 16MB and must be an Excel spreadsheet<br />@(Html.Kendo().Upload().Name("files").ShowFileList(true).Multiple(true).Messages(msg => msg .StatusUploaded("Response Status Goes Here?") .StatusFailed("statusFAiled") .StatusUploading("Uploading").Async(a => a .AutoUpload(true) .Save("Save","FileUpload") ) .Events(e => e .Success("onSuccess") ) )<div> @Html.ActionLink("Back to List", "Index")</div><script type="text/javascript">function onSuccess(e) { alert("Status: " + e.response.status);}</script>Controller:
public ActionResult Save(IEnumerable<HttpPostedFileBase> files){ foreach (var file in files) { string UPLOADSDIRECTORY = Server.MapPath("~/App_Data/uploads"); // Verify that the user selected a file if (file != null && file.ContentLength > 0) { // extract only the filename var fileName = Path.GetFileName(file.FileName); /* check the first three letters of the extension for xls - there are far too many endings for Excel to check all of them */ if (Path.GetExtension(file.FileName).Substring(1, 3) == "xls") { // store the file inside ~/App_Data/uploads folder var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName); FileInfo fInfo = new FileInfo(path); if (!(fInfo.Exists)) { file.SaveAs(path); var dataFile = new FileSpec { FileName = fileName }; db.FileSpec.Add(dataFile); db.SaveChanges(); // if successful, then redirect to the Edit page so the user can fill in the tab name while it's still fresh in their mind return Json(new { status = "OK" }, "text/plain"); } // TODO: redirect to error message because the file already exists return Json(new { status = "Overwritten" }, "text/plain"); } // TODO: redirect to error message because the file was not an Excel file (as determined by extension) return Json(new { status = "Rejected" }, "text/plain"); } } // default to Default status return Json(new { status = "Default" }, "text/plain");}