MVC3 Managing Remote Validation Exception

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

Answers


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?


Need Your Help

Gradle and proguard: could not find method runProguard() for arguments

android gradle proguard

I've configured the build.gradle as suggested by Proguard Gradle manual

R.id value requirements

android android-layout

I am currently working on an app, and I have noticed that if I assign any element (e.g. Textview) a numeric id value (such as android:id="@+id/1") - I get an error and it will not compile until I a...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.