简体   繁体   中英

Alternative To Exception Control Flow in ASP.NET MVC

I have read that exception control flow is a bad idea.

if(products.length == 0)
   throw new CustomException("Product is required");

I am using ajax at the moment for my requests and if a 500 error happens I catch them in an Exception filter that returns the exception in a strongly typed object that is sent to the client in JSON to be shown in a popup. In an ASP.NET MVC applicacation what is the better alternative and an example?

如果这是出于模型验证的目的,则最好使用数据注释等标准技术,或者,如果您像我一样,发现它们在复杂的验证场景中难以使用,则还可以签出FluentValidation.NET

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM