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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:07:23+00:00 2026-05-31T13:07:23+00:00

I have a MVC 3 project that uses Entity Framework. I can successfully update

  • 0

I have a MVC 3 project that uses Entity Framework. I can successfully update entities like this:

[HttpPost]
publiv RedirectResult Update(MyEntity entity)
{
    if(ModelState.IsValid)
    {
        this.entityRepository.Update(entity);
        return RedirectResult(".../Admin");
    }
    return RedirectResult(".../UnssuccessfullOperation");
}

Now the problem arised when I added DateTime property to my entities. If I do not add the @Html.HiddenFor for my DateTime property the date of my entity is 01.01.0001 (or DateTime.Min), which obviously cannot be saved to the database. If I add the hidden input the date is rendered but on update my ModelState is not valid and I guess this is due to the fact that the datetime is passed as a string.

Now there is one solution, but it seems a little strange – to not render Html.Hidden in the view and to use the datetime from the entityRepository like this:

entity.DateSomething = this.entityRepository.GetSingle(entity.ID).DateSomething;

but it does not seem very correct. Are there any other better options in that case?

  • 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-31T13:07:24+00:00Added an answer on May 31, 2026 at 1:07 pm

    If I add the hidden input the date is rendered but on update my
    ModelState is not valid and I guess this is due to the fact that the
    datetime is passed as a string.

    No, I suspect that it’s due to the culture setting in your application and the datetime format used in the hidden field. They probably don’t match.

    Take a look at the following blog post which covers the different issues that arise when parsing dates and how the format will depend on whether you are doing a GET or POST request and also a possibility to write a custom model binder to use a fixed format for dates.

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

Sidebar

Related Questions

I have an ASP.NET MVC 3 (using Entity Framework 4.2) application that uses transactions
I have a project that uses MVC 3 and Entity Franework. The site works
I have a new MVC project which uses the entity framework. I'm spitting out
Hi I have a Visual Studio solution and an ASP.NET MVC project that uses
I have an Asp.net MVC project that modestly uses jQuery scripts. My views also
I have an MVC project that I would like to write in .NET 4.0
I have recently started a personal project that uses ASP.NET MVC (RC1 at the
I have an ASP.NET MVC project that uses a SQL Server Compact database. I
I have a asp.net project that uses mvc-mini-profiler. I was using version 1.7 of
I have an asp.net mvc project that uses some search methods in a seperate

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.