Return metadata from controller on success?

2 posts, 0 answers
  1. Tom
    Tom avatar
    21 posts
    Member since:
    Apr 2016

    Posted 25 Aug 2017 Link to this post

    I have an Upload element that needs to receive data from the controller upon a successful upload, but I can't seem to find a way to make this work. My Upload looks like this:

        .Async(async =>
            async.Save("ReplaceDocument", "Library",new { DocumentId = Model.Id})
        .Events(e => e

    This saves to an action called ReplaceDocument in my Library controller, and includes the DocumentId from the Model. This all works great.

    ...but that ReplaceDocument action needs to return some data to the page. I understand that in the simplest version of this scenario, the action should simply return a string with an error message, or just an empty string if the upload is considered a success. I need to return more data. But how?

    If I amend the ReplaceDocument action, and make it an ActionResult, I can return a json:

    return Json(new { status = "OK", LastUpdatedUTC = lastUpdated }, "text/plain");

    ...or perhaps:

    return Json(new { status = "Access denied.", LastUpdatedUTC = lastUpdated }, "text/plain");

    I can retrieve this response data from the UploadSuccess js function. The second example given above should obviously indicate a fail state to the user, but I cannot find a way to tell the Upload element when the file was not accepted.

    Is there something I am missing? How do I trigger a fail state? Or is there a better way to receive data from the save Controller?

  2. Tom
    Tom avatar
    21 posts
    Member since:
    Apr 2016

    Posted 25 Aug 2017 in reply to Tom Link to this post

    Nevermind, figured it out.

    With the controller action as an ActionResult, a fail state is returned with:

    return Content("Error Message Here");

    And a success state can be returned with either the same, but with an empty string, or any JSON.

Back to Top