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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:29:08+00:00 2026-05-28T21:29:08+00:00

i have built an api and need to validate input objects passed as parameters

  • 0

i have built an api and need to validate input objects passed as parameters to controller actions.
Sometimes the same input class will have differing compulsory properties for different actions.

so

public class test
{
public ActionResult Create(User user)
{
  //here user_name must be present but no user_id
}
public ActionResult Delete(User user)
{
  //here only user_id must be present.
}
}

I have had a look at fluentValidation.net but it seems one has to create rules on a per class basis not class/action.

thanks.

  • 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-28T21:29:08+00:00Added an answer on May 28, 2026 at 9:29 pm

    What is a User?

    I don’t mean in the sense of where is the class defined, but in the sense of what does it physically mean in the domain? It sounds like you’re trying to get it to mean multiple things.

    Instead of trying to fit these actions into a model for the domain, create action models for them. Something like this:

    class CreateUserAction
    {
      public string Username {get; set;}
    }
    
    class DeleteUserAction
    {
      public int ID {get; set;}
    }
    

    Then use these in your action methods:

    public ActionResult Create(CreateUserAction user)
    {
    }
    
    public ActionResult Delete(DeleteUserAction user)
    {
    }
    

    This will break out the different purposes into different classes, in accordance with the single responsibility principle. Now the User class can focus on simply representing a user object, as opposed to sometimes representing a not-yet-created user or sometimes representing only the ID of a user object, etc.

    One major benefit here is that you can specify the validation rules directly in the class. With this approach, a User object can always require a Username and an ID to be valid. Whereas a CreateUserAction object doesn’t even have an ID (since it doesn’t need one) and a DeleteUserAction object doesn’t have a Username (since it doesn’t need one).

    You can further add additional fields as needed. For example, the CreateUserAction object will likely have other fields to describe the user being created. (It may even have fields that don’t go on a User object at all, but would be translated into some other object in the domain.) However, the DeleteUserAction may never need anything more than an ID (and, as suggested by SLaks, can probably be replaced with just an int for that action method, but that’s up to you).

    Clearer roles and responsibilities for classes, fewer partially-initialized half-objects.

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

Sidebar

Related Questions

I have a project built and packaged with a specific version of jsp-apiand servlet-api
I have built a number of asp.net servercontrols into a class library, & I
I have a fairly complex Rails app built on top of Twitter's API, and
i have built a solution around google maps api but realized that it doesn't
I have built an MSI that I would like to deploy, and update frequently.
I have built a simple C#.Net app on a M/C with only .Net FX
I have built a web page which contains a Crystal Report built using the
I have built an application in C# that I would like to be optimized
I have built a .dll under WinXP that claims it can't find DWMAPI.DLL when
I have built a CFC designed to serve as a dynamic, aging cache intended

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.