1

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?

Edited by alc6379: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by __avd
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.