Reputation: 4809
In one of the MVC 5 tutorial, they have declared the validation attributes directly on the models. Also, they are passing the model directly to the view. Previously, we have used view models to handle this kind of behavior. Please provide your thoughts which approach to follow.
http://www.asp.net/mvc/tutorials/mvc-5/introduction/adding-validation
Upvotes: 1
Views: 416
Reputation: 8168
Personally i prefer the view model approach because:
When to not use view models?
Basically only in cases when you want to quickly try something out say you are building a prototype which will be not used in production environment.
Upvotes: 1
Reputation: 7215
The better option is to use ViewModels. It's better because you have more control over what gets displayed where.
When you start to build applications that are NOT simply data entry, you run the risk of having to do something silly like the following:
There is a User table with 30 fields for anything from password, date entered, date last updated, delivery address, email, policiy number, etc.
The client asks you to build a Forgot Password page. If you use a DB object like the tutorials show, you're going to have to put the other 29 fields in hidden fields and pass them along.
That's the most basic problem you'll run into. Real world problems are much worse than that. Especially when you start building complex master-detail forms.
Upvotes: 0