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

  • Home
  • SEARCH
  • 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 6328423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:27:20+00:00 2026-05-24T17:27:20+00:00

How do I avoid needing to repeat validation rules on both my ViewModels and

  • 0

How do I avoid needing to repeat validation rules on both my ViewModels and business/domain objects?

For example I can use DataAnnotation attributes on my ViewModel, and this will give me client and server side validation in my MVC web app. But this ViewModel will then generally be mapped to a business/domain object and given to a service preform some business logic, meaning validation will have to happen again, often with the same or simular rules. Is there anyway round this?

  • 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-24T17:27:20+00:00Added an answer on May 24, 2026 at 5:27 pm

    I think what you’re describing is normal and acceptable. Consider your UI and data annotation as the friendly UI validation that is capable of showing users immediately any validation problems with the data entered.

    I would consider your Business/Domain object’s validation to be the complete validation, not just validating values but enforcing business rules (i.e. – Add Item to Cart –>Is the Item in Stock?)

    Then there is always back end validation that is often enforced by the database (i.e. Allowing Nulls in a column). Unless your database allows nulls in all fields, your actually performing validation in more than just the two places you mentioned, and this I think is a good thing.

    I think the bottom line is that you probably want your Business/Domain objects to enforce all validation, and your client side and back end validation to simply enforce the most basic.

    Hope that helps.

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

Sidebar

Related Questions

Is there a better way of modeling data in F# to avoid needing it?
After trying to avoid JavaScript for years, Iv started using Query for validation in
How can you avoid circular dependencies when you're designing two classes with a producer/consumer
How can we calculate x-height of a font (typeface) without needing .NET 3.0 or
One often reads how it's worth designing your code to avoid needing to make
To avoid magic numbers, I always use constants in my code. Back in the
I'm trying to avoid double up on my validation and want to know if
Is it possible to read in a txt file using sqlcmd, to avoid needing
I find myself needing to preform the same actions on both HtmlControls and WebControls.
How do I avoid read locks in my database? Answers for multiple databases welcome!

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.