Specifically, let’s implement a “Create” form that enables a user to enter friend data: We want to ensure that the information entered is valid before saving it in a database – and display appropriate error messages if it isn’t: We want to enable this validation to occur on both the server and on the client (via Java Script).
We also want to ensure that our code maintains the DRY principle (“don’t repeat yourself”) – meaning that we should only apply the validation rules in one place, and then have all our controllers, actions and views honor it.
This is the second in a series of blog posts I’m doing on the upcoming ASP. This blog post covers some of the validation improvements coming with ASP. Validating user-input and enforcing business rules/logic is a core requirement of most web applications. NET MVC 2 includes a bunch of new features that make validating user input and enforcing validation logic on models/viewmodels significantly easier.
Suggested Post, Nothing shocks me, I'm a Software Engineer. I live in World Wide Web and from there take care of this website.
This website communicates about my work, learning and experience.
If the posted form input is invalid, the action method redisplays the form with errors: After we’ve implemented our controller, we can right-click within one of its action methods and choose the “Add View” command within Visual Studio – which will bring up the “Add View” dialog.
We’ll choose to scaffold a “Create” view that is passed a Person object: Visual Studio will then generate a scaffolded view file for us under the \Views\Friends\ directory of our project.