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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:00:18+00:00 2026-05-20T20:00:18+00:00

Desired behavior An undecorated non-nullable value-type property in a model automatically gets a validation

  • 0

Desired behavior

An undecorated non-nullable value-type property in a model automatically gets a validation message “A value is required” added by DefaultModelBinder. I’d like it to instead display “A value is required for {Property DisplayName}”.

I can get this to work exactly like this, for DataAnnotated properties, using a string.format template. I can also change the default literal string to display from DefaultModelBinder in this circumstance. I’ve added a templated string as a resource: PropertyValueRequired -> "Information is required for {0}", as per:

Asp.Net MVC 2 – Changing the PropertyValueRequired string

Changing the default ModelState error messages in ASP.NET MVC 3

Examples here on StackOverflow indicate it is possible, both for MVC DefaultModelBinder and for DataAnnotations Validator. In both links above, the asker indicates he’s doing it for DefaultModelBinder (but can’t get other aspects working).


Observed behavior

Unfortunately, it outputs the {0} verbatim from MVC DefaultModelBinder (where I instead want the DisplayName inserted).

Are the posts above misleading? Does MVC3 support a format string for PropertyValueInvalid but not PropertyValueRequired? By convention, should I only be using DataAnnotation, and if I see the DefaultModelBinder message does it mean I haven’t handled/decorated sufficiently?

I think, in the following post, Darin Dimitrov may be saying that it isn’t possible to use a template. Quote: “override the default required error message … globally, which would be useless.”

ASP.NET MVC – Custom validation message for value types


Why I want to do this (prompted by an answerer asking)

  • When I bind to a built-in complex type, like a Dictionary<string, int>, there is no way to decorate the (int)Value with a validation message, so I get a generic validation message (DefaultModelBinder’s, not DataAnnotation’s) for each member of the dictionary.
  • I expected (naturally, I think) the localized value-required resource message parsing to work similarly regardless of which layer catches it.
  • I disabled AddImplicitRequiredAttributeForValueTypes as a popular method to address checkbox and date/time binding issues I was having, which seems to exacerbate this functional disparity.
  • Seeing the names in a section validation message of errant undecorated fields helps reduce debug time.
  • 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-20T20:00:19+00:00Added an answer on May 20, 2026 at 8:00 pm

    The answer is MVC3 does not support this. From the MVC source:

    PropertyValueInvalid

    string displayName = propertyMetadata.GetDisplayName();
    string errorMessageTemplate = GetValueInvalidResource(controllerContext);
    string errorMessage = String.Format(CultureInfo.CurrentCulture, errorMessageTemplate, modelState.Value.AttemptedValue, displayName);
    modelState.Errors.Remove(error);
    modelState.Errors.Add(errorMessage);
    

    PropertyValueRequired

    bindingContext.ModelState.AddModelError(modelStateKey, GetValueRequiredResource(controllerContext));
    

    I didn’t look further, but I suppose it is probably related to lack of model member access in some missing value scenarios.

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

Sidebar

Related Questions

The desired behavior is akin to the mirrored text editing field provided in Excel
I am having problems getting the desired behavior out of these few classes and
Example of failure: http://progamonth.com/files/testfile.html Desired Behavior: Ideally, any headers with a colspan shouldn't affect
I am creating a app in Java. I need to provide additional behavior when
When writing some rspec today, I came across some unexpected behavior with comparing Date
I'm creating a form using the Content Construction Kit (CCK) in Drupal5. I've added
Ok so I'm having bit of a problem with my Hibernate mappings and getting
I've noticed that whenever I write a program that uses std::cin that if I
Is there an easy way to exclude a control bar from the dock state
In a standard WinForms application, is it possible to have a scenario like 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.