954,595 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ASP.NET MVC2 model usage

Hey gang,

Looking for some opinions here. I'm working in an ASP.Net MVC2 application. We've built a collection of "domain objects", ie, the data that represents our "real world" problem we're going to solve, and it's also the representation of what will be serialized to the database. Each of these objects has been decorated with DataAnnotations Attributes to denote which properties are required. We plan on doing data validation before the object is persisted to the database.

The app itself is kind of like a "wizard"-- we're going to be configuring various parameters on one of the domain objects we're working with. But, each page of the wizard might be a subset of properties that the domain object might have. We're going to need to have validation on each of those pages, to make sure all required values are input.

Here's my question: If you were in this situation, what you use as your Model for each of these pages? Would you use the entire domain object, or would you build a view-specific model that is a subset of the domain object's properties, then validate that? I'm leaning towards the latter, because it seems cleaner. At some point, you'd take the 3-4 view-models and populate the domain object from those. Then, you'd validate the domain object, and persist that.

Am I off base here? MVC is kind of misleading of a term, in that the "Model" isn't actually what's getting persisted, it's just the data a specific view needs to get its job done.

edit:

As a followup, here's a link I found about doing partial validation on a single domain object:

http://blog.stevensanderson.com/2010/02/19/partial-validation-in-aspnet-mvc-2/

So you can validate a subset of properties on one object, but it just seems really ugly... My argument AGAINST this approach is that reusing the same object in this case just seems lazy-- why not go on and create a view-model specific to your view, and work WITH the platform?

alc6379
Cookie... That's it
Team Colleague
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147
 

You are right Alex and I agree. What I think that the pain points in ASP.NET MVC are setting up the models - models validation.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: