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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:06:25+00:00 2026-05-15T00:06:25+00:00

I am working in an ASP.NET MVC Application. I have a view model as

  • 0

I am working in an ASP.NET MVC Application. I have a view model as follows:

public class SampleInterestViewModel
{
   //Properties defined
   //One such property that shows an error in ModelState is as follows
   public DateTime? SampleDate { get; set; }
}

From UI Perspective user can enter date as mmddyyyy. And when user enters in such format say
01012001, my ModelState.IsValid code piece in controller returns false. When I did a quick watch in ModelState, I see an error for the propery “SampleDate”, saying “The Value 01012001 is not valid for SampleDate”.

In my modelbinder, during the OnModelUpdated event I tried to format the value 01012001 to 01/01/2001 and assigned it back to SampleInterestViewModel.SampleDate thinking that ModelState.IsValid might return true without that error. But still ModelState.IsValid is false and I when I looked in to the ModelState dictionary, this particular property still has that errors in its collection.

Lastly I tried to format 01012001 and update the value 01/01/2001 directly to the Property SampleDate in the ModelState dictionary. But still ModelState.IsValid is false showing the same error for the SampleDate property. Can’t figure out why ModelState.IsValid works and how and when it gets set to false.

If the User enter 01012001 in the UI, I still need to format it in the modelbinder to 01/01/2001 and make sure that ModelState.IsValid it true so that the rest of my controller code can work as expected. In the UI I am doing an AjaxSubmit to post the sampleDate value.

Any thoughts or comments.

  • 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-15T00:06:26+00:00Added an answer on May 15, 2026 at 12:06 am

    I can see a few solutions:

    1. After fixing the format in your model binder, you could clear the ModelState error with ModelState["SampleDate"].Errors.Clear();.
    2. Use JavaScript to validate the input to force the user to enter the correct format.
    3. Use JavaScript to change the format for the user before form post.

    I think a combination of 1 and 2 is your best bet.

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

Sidebar

Related Questions

I am working on an ASP.NET MVC application that contains a header and menu
I am working on an ASP.NET MVC application where I need to export data
I'm working on an ASP.NET MVC application. The app is broken up into a
I'm working on an asp.net-mvc application. The linq data context is being passed into
I upgraded a large ASP.NET MVC application I've been working on to the latest
I am currently working on my first asp.net mvc application. I am trying to
I'm trying to get the MVCToolkit working with an ASP.NET MVC Beta application and
I'm currently working on a blog application in ASP.NET MVC. I can't quite figure
I've been working with ASP.NET MVC for the last few weeks, learning as I
I've just started working with ASP.NET MVC now that it's in beta. In my

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.