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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:36:21+00:00 2026-05-27T10:36:21+00:00

I am somewhat new to MVC 3 so this could be something simple. I

  • 0

I am somewhat new to MVC 3 so this could be something simple. I have a Compact SQL 4 database. There is a Post object that has a Contents (string), Subject (string), When (DateTime) and Reposted (DateTime nullable) fields. During the Create’s Post method, I manually force the When property to be DateTime.Now and it works great.

However, on my Edit View, I do NOT want to show this field or at least not let it be an editable field. When I do NOT put it as an editable field on the Edit View and they change say the Contents and then click Save I get the message:

An overflow occurred while converting to datetime.

During the Edit Postback, I am setting the Reposted field to DateTime.Now so it has to be the When field. When I debug on that postback I see that the “Post” object is only filled in with values of the fields I am displaying on the screen. So I decided to just grab the When field out with a LINQ query directly from the data but when I get to the SaveChanges it fails and says the following:

An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key

So how can I update an object and let the user only change a few pertinant fields? Seems like the Post object is not getting ALL of the existing values since they are not showing on the screen. How can I fill that object completely?

Edit: Here is the Post method.

[HttpPost]
public ActionResult Edit(Post post) {
  if (ModelState.IsValid) {
    db.Posts.Attach(post);

    int Successes = 0;
    int Failures = 0;

    this.SendEMail(post, out Successes, out Failures);
    post.Successes = Successes;
    post.Failures = Failures;
    post.Reposted = DateTime.Now;

    db.ObjectStateManager.ChangeObjectState(post, EntityState.Modified);
    db.SaveChanges();
    return RedirectToAction("Index");
  }

  return View(post);
}
  • 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-27T10:36:22+00:00Added an answer on May 27, 2026 at 10:36 am

    Include a hidden field in your view for the fields that you do not want to display e.g.

    @Html.HiddenFor(model => model.When)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am somewhat new to R, and i have this piece of code which
I am somewhat new to jQuery and I have a problem with something I
This is somewhat new territory for me. I'm using MVC3 with SQL CompactEdition version
I'm somewhat new to MVC (but not ASP.NET). Is there a similar concept in
I'm somewhat new to Spring (using 3.0), so I'm hoping there is a simple
I am somewhat new to using JPA -- I'll put that out there right
I'm somewhat new to the ASP.NET MVC architecture and I'm trying to sort out
I am somewhat new to LINQ and have a quick question regarding deleting. Say,
I'm somewhat new to OpenGL. I've used it for extremely simple stuff like rendering
I'm somewhat new to object oriented programming in Javascript and I'm trying to build

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.