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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:33:53+00:00 2026-05-14T00:33:53+00:00

I’m using DataAnnotations attributes to validate my model objects. My model class looks similar

  • 0

I’m using DataAnnotations attributes to validate my model objects. My model class looks similar to this:

public class MyModel
{
    [Required]
    public string Title { get; set; }

    [Required(ErrorMessage = "At least one editor is required.")]
    public List<User> Editors { get; set; }
}

public class User
{
    public int Id { get; set; }

    [Required]
    public string FullName { get; set; }

    [Required]
    [DataType(DataType.Email)]
    public string Email { get; set; }
}

My controller action looks like:

public ActionResult NewItem(MyModel data)
{
    if (!this.Model.IsValid)
    {
        // invalid processing
    }
    // valid processing
}

User is presented with a view that has a form with:

  • a text box with dummy name where users enter user’s names. For each user they enter, there’s a client script coupled with ajax that creates an <input type="hidden" name="Editors[0].Id" value="userId" /> for each user entered (enumeration index is therefore not always 0 as written here), so default model binder is able to consume and bind the form without any problems.
  • a text box where users enter the title

Since I’m using Asp.net MVC 2 RTM which does model validation instead of input validation I don’t know how to avoid validation errors. And since users provide User.Id, the whole User object instance is being validated. Which doesn’t bother me, as long I would know how to exclude other properties’ validation.

The thing is I have to use BindAttribute on my controller action. I would have to either provide a white or a black list of properties. It’s always a better practice to provide a white list. It’s also more future proof.

The problem

My form works fine, but I get validation errors about user’s FullName and Email properties since they are not provided. I also shouldn’t feed them to the client (via ajax when user enters user data), because email is personal contact data and is not shared between users.

If there was just a single user reference on MyModel I would write

[Bind(Include = "Title, Editor.Id")]

But I have an enumeration of them. How do I provide Bind white list to work with my model?

One possible solution

I could create a separate view model for User just for the sake of entering MyModel objects. I would put actual validation attributes and omit properties I don’t need.

public class MyModelUser
{
    [Required]
    public int Id { get; set; }
}
  • 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-14T00:33:53+00:00Added an answer on May 14, 2026 at 12:33 am

    I ended up using a separate view model (as described in One possible solution in my question), that can be fully validated. It’s a workaround and I would still like to know how to do it properly.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Most of this is possible to do yourself. Calling the… May 16, 2026 at 11:20 am
  • Editorial Team
    Editorial Team added an answer using (SaveFileDialog dialog = new SaveFileDialog()) { dialog.Filter = "Text… May 16, 2026 at 11:20 am
  • Editorial Team
    Editorial Team added an answer This should get you most of what you're looking for:… May 16, 2026 at 11:20 am

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

Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
In order to apply a triggered animation to all ToolTip s in my app,
I want use html5's new tag to play a wav file (currently only supported
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.