すべての DbEntityValidationException メッセージをキャッチし、ModelState に追加して、@Html.ValidationSummary() を使用して ModelState エラーを表示する例外の原因となったビューに進みたいと思います。
/Shared/Error ビューへのリダイレクトのみを記述した HandleErrorAttribute の Extension クラスを除いて、すべてが機能しています。空白のビューを返します
public class HandleLogErrorAttribute : HandleErrorAttribute
{
//Log the filterContext Exception Details
public override void OnException ( ExceptionContext filterContext )
{
var exception = filterContext.Exception;
var controller = ( (Controller) filterContext.Controller );
//Log here
//Add Validation Exception messages to ModelState here
if ( exception is DbEntityValidationException ) {
var dbEx = filterContext.Exception as DbEntityValidationException;
foreach ( var ves in dbEx.EntityValidationErrors ){
foreach ( var ve in ves.ValidationErrors ) {
controller.ModelState.AddModelError( string.Empty, ve.ErrorMessage );
}
}
//HOW to continue to the View that caused the exception with the model state now filed with the Validation Exceptions?
}
}
}