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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:30:23+00:00 2026-05-16T01:30:23+00:00

So I have been using data annotations for my validation in an MVC project

  • 0

So I have been using data annotations for my validation in an MVC project and they seem to work in most scenarios.

Here are two examples in my current project where they don’t seem to fit and I am unsure of the best place to put the validation.

1) I have a Join League page that contains a form where the logged in user enters their team name and clicks to join the league. When they submit the form i need to make sure that the current user doesn’t already have a team in the league. So it basically needs to query the db for that user id and league id to make sure no team exists for the user. My ViewModel does not contain user id, since it is not relevant to the view.

2) On this same page, I also need to make sure the team name is unique. This is easy if you are just looking to see if it exists in a table. You create a custom validation attribute that query’s a table for the value of the field. However i need to see if it exists in a table for a certain league id. (the league they are joining.)

It doesn’t seem like Data Annotations are an ideal solution for anything other then trivial validation. My current solution is to query the db at beginning of post action method, and add the error to the ModelState manually. (yes, terrible)

Any ideas?

  • 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-16T01:30:24+00:00Added an answer on May 16, 2026 at 1:30 am

    I think it may help to put some thought into the difference between Input Validation and Business Logic. Ayende has some thoughts on this here

    Rules like ‘When they submit the form I need to make sure that the current user doesn’t already have a team in the league’ sounds like Business Logic, not Input Validation, and you may want to handle it in a different way. This logic could, for instance, go into a ‘CanSave’ method on a ‘User’ class or something similar – the key thing is to separate this from Input Validation if you can.

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

Sidebar

Ask A Question

Stats

  • Questions 529k
  • Answers 529k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I have added an issue on the Elmah web site… May 16, 2026 at 11:23 pm
  • Editorial Team
    Editorial Team added an answer If subview is a subview of view then whether it's… May 16, 2026 at 11:23 pm
  • Editorial Team
    Editorial Team added an answer Use socket_getpeername May 16, 2026 at 11:23 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am developing an ASP.NET MVC app and I've been looking into using Data
I have been using a driver to test one of my data structures(Binary Search
I have been experimenting recently with Silverlight, RIA Services, and Entity Framework using .NET
I have been using a stored procedure for more than 1.5 years. But I've
I have been using the following code for months (without problem) in a .NET
I have been using Grails for last 3 weeks (learning and working). I have
I have been using WinForms since the first framework introduced and invested a lot
I've been using mySQL for an app for some time, and the more data
I have a connection protocol that has been defined by our customer. Data are
I'm trying to decide what validation approach to take for a new ASP.NET MVC

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.