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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:27:41+00:00 2026-06-07T06:27:41+00:00

My MVC action method receives an entity object (Page) that the default model binder

  • 0

My MVC action method receives an entity object (Page) that the default model binder creates from form collection data. Some of the fields are wrong or null because they were not sent in the request to the server, for example I do not send “CreateDate” and the default model binder sets this property to some default value which I don’t need.

Once the object is attached it of course tries to persist all the values (including invalid/not needed ones to the database). I could of course assign manually on a per property basis but was wondering if maybe I can somehow flag a property so it is not persisted when EntityState is set to modified and SaveChanges() is called..

public ActionResult SomeMethod(Page page)
{
page.ModifyDate = DateTime.Now;

       _db.NewsPages.Attach(page);
                _db.ObjectStateManager.ChangeObjectState(page, System.Data.EntityState.Modified);
                _db.SaveChanges();
                _db.Dispose();

}
  • 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-07T06:27:43+00:00Added an answer on June 7, 2026 at 6:27 am

    The correct way to handle this is using different class for view model, attach empty entity to the context and assign real values per property (or let AutoMapper to handle this scenario) as @Darin suggested in the comment.

    If you want to go your way you must not change state of the POCO entity but you must change state of every changed property:

    public ActionResult SomeMethod(Page page)
    {
        page.ModifyDate = DateTime.Now;
    
        _db.NewsPages.Attach(page);
        ObjectStateEntry entry = _db.ObjectStateManager.GetObjectStateEntry(page);
        entry.SetModifiedProperty("ChangedPropertyName");
        // Do the same for all other changed properties
        _db.SaveChanges();
        _db.Dispose();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written an ASP.NET MVC action method that receives a .less file name, processes
I have an ASP.NET MVC project with a form. In the Action method that
I intended for this function to call my MVC action method that returns a
I have an ASP.NET MVC action method which uses model binding to accept a
i have a javascript object, obj , that gets passed to an mvc action
where does mvc stores the association between action method name and view page name?
I have a MVC action method from which I am returning the data as
In ASP.NET MVC the convention is that a controller action method should return an
I want to execute Java Script generated from an MVC action method, I read
My application makes several calls to an Action method (ASP .NET MVC) which returns

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.