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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:08:42+00:00 2026-06-11T00:08:42+00:00

Consider this model class: public class FooModel { public Person Manager { get; set;

  • 0

Consider this model class:

public class FooModel {
     public Person Manager { get; set; }
     public Person Employee { get; set; }
}

public class Person {
     [Required]
     public String Name { get; set; }
}

If the user provides a Name value in a form for the Manager but not the Employee then the ValidationSummary() will return the message “Name is required” without qualifying it further (i.e. it isn’t clear that Employee.Name isn’t set but Manager.Name is).

What solutions are there to this problem?

  • 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-11T00:08:44+00:00Added an answer on June 11, 2026 at 12:08 am

    The question here: ( How do I show a different Required message to instances of the same object in MVC3? ) has two answers.

    The first suggests flattening the ViewModel, in my case that would mean copying the Person members into FooModel twice, then I could set a customized validation message for both. I decided against this for obvious reasons (my Person class is considerably more complicated and also used elsewhere).

    The second answer suggests modifying ModelState’s error messages, which is what I do. I’ve already developed a way for ViewModels to modify their own validation so adding this trick was easy enough. I’ve added a [DisplayName] attribute like so (psuedocode):

    class FooModel : ICustomValidation {
        [DisplayName("Manager")]
        public Person Manager { get; set; }
        [DisplayName("Employee")]
        public Person Employee { get; set; }
    
        public void HandleValidation(ModelStateDictionary modelState) {
            if( modelState.IsInvalidByPrefix("Manager") ) {
                modelState.AppendErrorMessageDisplayPrefix( GetLocalisedDisplayName("Manager") );
            }
    

    if( modelState.IsInvalidByPrefix(“Employee”) ) {
    modelState.AppendErrorMessageDisplayPrefix( GetLocalisedDisplayName(“Employee”) );
    }
    }
    }

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

Sidebar

Related Questions

Let's consider this model class Session(models.Model): tutor = models.ForeignKey(User) start_time = models.DateTimeField() end_time =
Consider the following Django models: class Host(models.Model): # This is the hostname only name
Consider the following scenario: My form model public class PersonForm { @NotNull private String
Consider this simple Model and ViewModel scenario: public class SomeModel { public virtual Company
Consider I have the following classes as ViewModels public class Address { public String
Consider the following entity model: public class Agreement : Entity { public int AgreementId
Consider the following (simplified) domain model stored in RavenDB: public abstract class PriceCalculation {
Situation Consider I've got the following class structure: // a user model class UserModel
Consider the following Entity: @Entity public class Employee { @Id @GeneratedValue private Long id;
Consider the following Model: public class ExportRequestsFilter { [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = {0:dd/MM/yyyy})]

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.