how do I display status response next to file list?

1 posts, 0 answers
  1. Samuel
    Samuel avatar
    19 posts
    Member since:
    Aug 2012

    Posted 28 Sep 2012 Link to this post

    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...
    @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 />
    .Messages(msg => msg
        .StatusUploaded("Response Status Goes Here?")
    .Async(a => a
        .Events(e => e
        @Html.ActionLink("Back to List", "Index")
    <script type="text/javascript">
    function onSuccess(e) {
        alert("Status: " + e.response.status);

    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))
                        var dataFile = new FileSpec { FileName = fileName };
                        // 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");
Back to Top