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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:51:50+00:00 2026-06-11T20:51:50+00:00

we are building an ASP.Net MVC application, and we ask ourselve the question where

  • 0

we are building an ASP.Net MVC application, and we ask ourselve the question where we shoud put the validation logic for incoming data.

We already have the simple validation in place: these are attributes on the viewmodel, like [required], [numeric] , [email] etc. (this is open for discussion too, btw)

But now we have some more input validation: we want to validate if the id’s received from dropdownlists are genuine id’s.

For example: when we receive 91 as a countryid, i have to make sure 91 is a valid countryid and not a value ‘hacked into’ the form by a user. Because if it is not a valid countryid, my datalayer generates an error.

  1. Should i place this in the controllers action method, because that
    method knows what is right and what is wrong when the data from the request arrives?

  2. Should i place it in a VacancyValidator (the object is a Vacancy
    object) where i put all validation logic for all vacancy related
    viewmodels

  3. Should i place it in the ViewModel because it should know how to validate itself

  4. Should i create an attribute which validates the property which i place on the ViewModels property

  5. Should i place it in a Vacancy[thisviewmodelsname]Validator where i put all validation logic for this specific viewmodel

Any ideas appreciated….

  • 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-06-11T20:51:51+00:00Added an answer on June 11, 2026 at 8:51 pm

    We already have the simple validation in place: these are attributes
    on the viewmodel, like [required], [numeric] , [email] etc. (this is
    open for discussion too, btw)

    I would recommend FluentValidation.NET instead of Data Annotations which plays nicely with ASP.NET MVC. It provides a nice syntax for expressing complex validation logic between interdependent properties without writing millions of lines of plumbing infrastructure code (which is what you would have to do if you use Data Annotations and write a custom validator) and also allows you to unit test your validation logic very easily.

    Because if it is not a valid countryid, my datalayer generates an error.

    There you go – your data layer already handles this validation for you. But if you don’t want to leave it to reach the data layer then you could have a validation rule for this property on the view model. If you follow my previous advice about FluentValidation.NET you will already know where to put this rule – in the corresponding validator of your view model.

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

Sidebar

Related Questions

I'm building an ASP.NET MVC application. I will store a lot of data per
I'm building an ASP.NET MVC application with a form that needs validation. The majority
I am building an ASP.Net MVC 3 Web application with Entity Framework 4.1. I
I am building a web application using ASP.NET MVC that has two very distinct
I am currently building a very small/simple web application in ASP.NET MVC with ADO.NET
When building an ASP.NET MVC application with a goal of high availability, is it
I am building a asp.net mvc application. I want session to never expire, once
I'm building an asp.net MVC application where users can attach a picture to their
I am building an ASP.NET MVC web application using entity framework DbContext using the
I am building an asp.net mvc web application. Do I need to use captcha

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.