I want show a message in client when server is triggering an custom error upon uploading but i just cant get it to work. I can trigger other events and but i just cant get custom errors to work. Im using ASP.Net MVC and the ASP.NET MVC Helper.
How do i trigger a custom error from my controller and show the error in the client?
Server controller:
internal static void HandlerUploadFinising(object sender, UploadFinishingEventArgs args)
{
args.ServerMessage = "An error";
args.Cancel = true;
}
Client:
$("#imageUpload").bind({
iguploadfileuploaded: function (e, args) {
console.log('iguploadfileuploaded ', args);
});
Hey pytte,
In order to handle different uploaded files my suggestion is to configure your Upload Wrapper like:
@(Html.Infragistics().Upload() .ID("upload1") .ControlId("upload1") .MultipleFiles(false)
.Mode(UploadMode.Multiple) .AutoStartUpload(false) .Render() )
Just set MultipleFiles to be false and Mode to be Multiple. Now the event will fire for each uploaded file and you can return different message for each of them.
I finally got it to work. Thanks for your example. The problem was in my web.config, it pointed to an older version of Infragistics.Web.Mvc.dll that i had referenced.
The next question is, how can i trigger file specific error messages when i upload multiple files?
If i want to upload 10 different files and 2 files generates two different errors, how can i show the specific message to just that file?
Hello Pytte,
Let me correct myself, this issue is fixed and available in the last Service Release. I am attaching you a sample that is showing how to throw a custom error and show it in your view.
I hope that you will glad this approach.
Please have a look and let me know if you have any further questions.
Hello,
Now I understand you correctly.
In order to pass custom exception you will need to do it on FinishingUpload event for example.
internal static void igUpload_FinishingUpload(object sender, UploadFinishingEventArgs e) { e.ServerMessage = "My Custom Error"; e.Cancel = true; }
And in your view you can handle onError client event:
@(Html.Infragistics().Upload() .ID("upload1") .ControlId("upload1") .MultipleFiles(false) .Mode(UploadMode.Single) .AutoStartUpload(false) .Render() ) <div id="error-message" style="color: #FF0000; font-weight: bold;"></div> <script type="text/javascript"> $(function () { $("#upload1").bind({ iguploadonerror: function (e, args) { alert(args.errorMessage); $("#error-message").html(args.errorMessage).stop(true, true).fadeIn(500).delay(3000).fadeOut(500); } }); }); </script>
This should work, although there is an issue with that approach that is already fixed and should be available in the next service release (Future projection October 10, 2014).
I have implemented that callback, maybe i was a bit unclear in my first question but i was unable to get this to work properly.
How do i throw an custom error in the controller so it cant be shown in the client?
For an example, i want to check the resolution of a png file and run viruscheck after the file is uploaded.
If there is a working example of this scenario of this?