I am developing a MVC3 (razorview) application that makes use of the Telerik Controls. So what I am doing is the following:
I want to upload a file, do some validation. If the file is valid I want to give the user the option to upload the file permanently. If it is not valid, the errors are displayed and the user can't upload the file.
This is what I have so far:
Javascript code:
<script type="text/javascript">
function onSuccess(e) {
if (jQuery.isEmptyObject(e.response.errors) && jQuery.isEmptyObject(e.response.warnings)) {
$("#successmsg").show();
} else {
var errorMsg = "";
if (!jQuery.isEmptyObject(e.response.errors)) {
for (var i = 0; i < e.response.errors.length; i++) {
errorMsg = errorMsg + "<li>" + e.response.errors[i] + "</li>";
}
}
if (errorMsg != "") {
var strErrorContent = $("#errormsg_template").html();
$("#errormsg").html(strErrorContent.replace("{0}", errorMsg));
$("#errormsg").show();
}
}
}
Telerik component in view:
<p>
@Html.Telerik().Upload().Name("file_upload").Multiple(false).Async(settings =>
{
settings.AutoUpload(false);
settings.Save("Test", "Pricat");
}).ClientEvents(events =>
{
events.OnError("onError");
events.OnSuccess("onSuccess");
events.OnUpload("onUpload");
})
</p>
So this code is working for the validation part. The user selects the file, the file is uploaded and some internal processing is validating the message. If the message is valid, a successmessage is shown. If it not valid, the errors are displayed.
How should I proceed to add a button that does the upload (which is basically just another method call), without browsing to the file again?
So the following
settings.Save("Test", "Pricat");
should become
settings.Save("Upload", "Pricat");
So in the controller I have these 2 methods:
public ActionResult Upload(HttpPostedFileBase file_upload) { }
public ActionResult Test(HttpPostedFileBase file_upload) { }
What I had in mind: In javascript, if the e.reponse doesn't contain errors, display a button (ASP.NET button, another upload telerik button, I don't know..). When that button is clicked, it should call the "Upload" method in my controller. I just don't know how to send the file to that method
Does anyone know how to do this? Or any other suggestions are more than welcome!
I hope it is a bit clear.
Thanks in advance.
Best regards.