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:
@(Html.Kendo().Upload()
.Name("FileUploader")
.Multiple(false)
.Async(async =>
async.Save("ReplaceDocument", "Library",new { DocumentId = Model.Id})
.AutoUpload(true)
)
.Events(e => e
.Success("UploadSuccess")
)
)
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?