Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 597351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:16:15+00:00 2026-05-13T16:16:15+00:00

With the new ASP.NET MVC 2 validation features, we can decorate the properties of

  • 0

With the new ASP.NET MVC 2 validation features, we can decorate the properties of our domain model objects with DataAnnotations attributes that describe criteria for valid values. The DefaultModelBinder knows about this and populates ModelState.IsValid accordingly before a controller action is invoked. Since the validation rules are defined within the domain model, this is regarded as model-level validation. Scott Guthrie writes:

The benefit of implementing the rules within our Person object is that this will ensure that the validation will be enforced via any scenario within our application that uses the Person object […]

Strictly speaking, the rules are not really enforced in my opinion, since all the action methods need to check the ModelState.IsValid property and act differently depending on its value. Also, although the rules are defined in the model, they are applied in the presentation layer since that’s where all model binders live. But I guess this is just me being picky with the choice of words (or me just being plain wrong).

However, what about enforcing the validation rules at the domain model level? Steven Sanderson uses this approach in a post about the xVal validation framework where he writes:

Now, the model tier enforces its own validity by refusing to place bookings that don’t meet all validation and business rules.

In his example, the “booking manager” (which lives within the model) throws a special business rule exception when consuming code tries to place a booking that is invalid. Thus it is impossible for the consuming code to place an invalid booking, regardless of whether it checked the validity of the booking beforehand (through ModelState.IsValid or some other custom construct).

So my question is:

Assuming that there are validation rules defined at the model level, should they also be enforced within the model?

(Note that I’m really new to the concept of domain-driven design, so please bear with me if I haven’t used precisely the correct terminology.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:16:16+00:00Added an answer on May 13, 2026 at 4:16 pm

    Assuming that there are validation rules defined at the model level, should they also be enforced within the model?

    Yes. If you provide a way for the rules to be short-circuited, then they will be. Maybe not by you, and maybe no time soon, but surely by other developers in x weeks/months/years in the future.

    Plus there’s always the human error element – maybe one day when you’re tired or coding late at night, you incorrectly read this validation flag and are actually letting records through that don’t validate. (Don’t scoff, I’ve done it myself!)

    I now always make sure a record cannot get through to the database without being validated by the model.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to use the new client side validation features of asp.net MVC
I was reading this blog post on ASP.NET MVC 2's new model validation and
I'm trying to decide what validation approach to take for a new ASP.NET MVC
I'm using ASP.NET MVC 2 and using Microsoft's beautiful new 'DataAnnotations' to provide some
ASP.NET MVC Model Binding is still new to me and I'm trying to understand
I'm using the Data Annotation validation extensively in ASP.NET MVC 2. This new feature
I have a custom asp.net mvc class validation attribute. My question is how can
I am using DataAnnotations to enable client-side validation in an ASP.NET MVC 2 project.
http://www.asp.net/learn/mvc/tutorial-39-cs.aspx We are using the above guide to implement some validation in our ASP.NET
I have a new asp.net mvc project and i am trying to figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.