Question

i have the following problem: i'm using remote validation for validate a field and now i'm trying to manage exception

public class ValidationController : Controller
{
    List<string> values = new List<string>() { "AAAA", "BBBB" }; //blacklist

    public JsonResult NameAllowed(string ID)
    {
        throw new Exception();
        //return Json(!values.Contains(ID), JsonRequestBehavior.AllowGet);
    }

}

but in this case the form wasn't submitted (ERROR 500 through network capturing, dev toolbar) and doesn't appear any error.

  1. What is the best way to manage exception (for example Timeout and not predictable exceptions)?
  2. Exist a solution (any server side parameter) to skip these errors for submit the form?

Thanks in advance

Was it helpful?

Solution

Remote validation should ONLY be used as a graphical feedback to the client that prevents the user from sending useless data to the server. You should ALWAYS have a server side validation for everything you have to validate, and if you do, well, your form will be sent but not approved, and your validation error will be displayed along with a re-rendered form with your invalid inputs.

Take client side / remote validation as a "Pre-Validation" that has 2 purpose

  1. Prevent useless server-side processing
  2. Give a more responsive validation of data instead of waiting for the form to be submited.

They should however never be used to actually validate the data.

Edit

That said, how about just writing your validation code properly, using try catches and not letting any unhandle exception slip throught?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top