title: Kendo Upload Control, Pass custom error message back to view
body: <p>I am working with ASP.NET MVC3, Kendo UI, and Jquery.  I am trying to pass an error message back to the view when the processing of an uploaded file does not pass validation rules that we have.</p>
  
  <p>Here is my upload control in my view:</p>
  
  <pre><code>@(Html.Kendo().Upload()
    .Name("files")
    .Async(a =&gt; a
    .Save("SaveForm", "Home")
    .Remove("RemoveForm", "Home")
    .AutoUpload(true))
    .Events(events =&gt; events
    .Success("onSuccess")
    .Error("onUploadError")
    .Select("onSelect")
    ))
  </code></pre>
  
  <p>Here are the relevant parts of the SaveForm method in the controller:</p>
  
  <pre><code>try
  {
        FieldDefinitions = ProcessPDFFile(file.FileName);
  }
  catch (InvalidDataException ex){
      List&lt;String&gt; errors = new List&lt;String&gt;();
      errors.Add(ex.Message);
      Response.StatusCode = 500;
      Response.TrySkipIisCustomErrors = true;
  
      //return Json(new { success = false, statusText = "error error" }, "text/plain");
      //ModelState.AddModelError("pp", ex.Message);
      //var result = ModelState.ToDataSourceResult();
      //return Json(errors, JsonRequestBehavior.AllowGet);
      //return Json(new { status = "OK" }, "text/plain");
      //return Json(String.Concat(errors.ToArray()));
      //return Json(new AjaxResult(false, ex.Message, errors ));
  }
  </code></pre>
  
  <p>Here is my Jquery error function:</p>
  
  <pre><code>function onUploadError(e)
  {
      alert(e.message);
  }
  </code></pre>
  
  <p>In my controller, ex.Message is a custom error message and I want to pass it back to the view for display.  You can see all the different variations that I tried to pass it back by looking at the commented out lines of code in my controller.</p>
  
  <p>The jquery error function is getting executed.  The only problem is I can't seem to get my custom error message in the jquery. </p>
  
  <p>When evaluating e.XMLHTTPRequest </p>
  
  <p>it has the following:</p>
  
  <p>responseText = "Error trying to get server response"
  Status = 500
  StatusText = "error"</p>
  
  <p>So how do I get my custom error message into one of the above elements of XMLHTTPRequest?  I assume the return on my controller needs to be modified somehow.</p>