Hello!
I would like to upload a file to the server and also write some data into SQL database after the user fills a form with those metadata. I used the widget this way:
@Html.Kendo().Upload().Name("docUpload").Async(a => a.Save("UploadFile", "Dokumentum", new { id = Model.Id }).AutoUpload(false)).Multiple(true).Events(ev => ev.Upload("onUpload").Error("onError").Success("onSuccess"))
The widget first calls onUpload javascript that calls the action that stores the metadata in SQL (input parameter is json). This action returns empty content if successful, or content with the error message if fails.
Either the first action was successful or failed, the widget calls the UploadFile action, that stores the file on the server (input parameter is HttpPostedFileBase). This action also returns with an empty content if it was successful.
This is works perfectly. My problem is, that what if the metadata writing fails (because of some validation or anything) and the file will be copied to the server. Or the metadata writing is successful but the file store fails. I would like the widget returns successful message only if both are successful or error message if one of them fails (of course the other action shouldn't be executed).
Here's the onUpload javascript:
function
onUpload(e){
var
json=
new
Object();
json[
"json"
]=JSON.stringify({...blah-blah});
$.ajax({
url: '@Url.Action(
"Save,"
Controller"),
async:
false
,
type:
"POST"
,
data:json,
dataType:
'json'
,
success:
function
(result){},
error:
function
(error){}
});
}
Thanks for your help