Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>So, in general in ASP.NET MVC you need to handle 2 kinds of errors: Validation errors, and System errors.</p> <p>For System errors, those occurring because of some system rules violation (like foreign key constraint violation in database during insert), you should use try-catche operator and then pass them to the view in some way to show them to the user.</p> <p>For validation errors, you should read about ASP.NET MVC Validation:</p> <ul> <li><a href="http://www.asp.net/mvc/tutorials/validation-with-the-data-annotation-validators-cs" rel="nofollow">Validation with the Data Annotation Validators</a> - here you can see how to validate simple validation rules using built-in annotation attributes.</li> <li><a href="http://www.asp.net/mvc/tutorials/validating-with-a-service-layer-cs" rel="nofollow">Validating with a Service Layer</a> - this is more advanced topic, where you can learn how to validate more complex validation rules (for example for inter-connected properties, etc.)</li> </ul> <p>So, as a conclusion, think of separating the concerns about domain/business functionality from the concerns related to validation. The only common thing they should have (in the perfect scenario) is a view where you show the results of validation.</p> <p>Personally I (taking 2-nd approach) even do a save in validation, so that Validation implementation knows about domain/business logic and manipulates it to validate all the rules. In the end of validation, if all rules were met, then it tries to save the data, and returns the validation error message in case of non-success. This is also a good start to go further and even localize your custom validation messages.</p> <p>I hope this helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload