Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Emitting Exceptions from LINQ to SQL classes in ASP.NET MVC Validation Summary

Recently while developing a sample application in ASP.NET MVC, I came across a peculiar situation. There was a LINQ to SQL class with several extensibility methods defined (OnXXXXChanging kind of methods where XXXX is the name of a property). The methods were performing some validation checks and in case of any violation were throwing exceptions. The LINQ to SQL class was working fine. However, at some places I wanted to display the validation errors (thrown by the class as exceptions) on the ASP.NET MVC views. That is where the problem began. No matter what exception you throw in the class the Validation Summary never displays the error message.

http://www.bipinjoshi.net/articles/e90a06d2-3c4e-4abd-9143-88f85bd49629.aspx