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 6977377
In Process

The Archive Base Latest Questions

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

Right now the application being built by our team uses the built in MVC

  • 0

Right now the application being built by our team uses the built in MVC attributes and a few home baked ones to validate the View Models. Because of best practice design principles, we have placed those same rules in the Logical Layer. This has unfortunately caused duplication of validation code.

In MVC3 at least, if JavaScript is disabled, these same attributes will still perform the validation they are meant to, so transforming a View Model in to a DTO and asking the Logical Layer to validate it is not an option because this process would have already been done by the framework.

I have not found the following SO post to be of any help. I have used MS Enterprise Library and the API did not sit well with our team.

Good practices for avoiding validation logic duplication when working with both domain objects and view models in ASP.NET MVC

I’m thinking that the best way to do this is to have the validation attributes bound at runtime to specific properties and have a dependency injection container do this. Is this possible or is there a different approach we could take?

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

    You are asking for multiple validation types to be performed here.
    You want client validation (it seems) and some other business validation layer.

    If thats the case the only choices as I see it are:

    1. duplicate the code (ya I know Im listing options)
      1a. use data annotations on your objects for client validation. Business layer validation happens however you define, and separate as a final check. If you use for instance the entity framework’s fluent API this is a standard route.
    2. client side validation is just that – helpers for client side. domain validation will happen upon save. This is ideally the more powerful approach, but isn’t as friendly when your domain objects don’t match property names on your view models, so you need to map domain errors to view model property errors which normally isnt too bad but can get iffy.
    3. implement IValidteableObject (and rid of client validation). This validation logic is then called from your logical layer and the model binder.
    4. You can inject code for validation, but its not pretty and Im not sure how reusable it is outside the MVC validation route.

    There may be other ways beyond this, but those are the main options as I see it.

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

Sidebar

Related Questions

Right now I have a few new applications being developed against an Oracle Database,
Right now I have an MVC application running on http://127.0.0.1:8081/ (it is actually running
Right now, I'm writing a small java application by my own, with few maven
I have an application right now that starts a process, then opens a file
I am using Asp.Net/C# and Visual Studio 2008 to build an application.Right now I
Right now whenever I run application It creates a file (file name specified in
Right now I'm working on a web application that receives a significant amount of
Right now, my application is using the c-ares asynchronous DNS resolver library on Windows
So right now I've developed an application that I'm trying to write an API
Right now I've got a mod_wsgi script that's structured like this.. def application(environ, start_response):

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.