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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:47:37+00:00 2026-05-23T12:47:37+00:00

I have a complex model class, of which only a few string columns should

  • 0

I have a complex model class, of which only a few string columns should be (and can be) edited. When I open and edit a couple of these columns and save the form, the string columns are posted back just fine, but the other (array) columns are null — this breaks the save to Entity Framework.

What’s the proper way to go about this with MVC3 and EF?

  • 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-23T12:47:38+00:00Added an answer on May 23, 2026 at 12:47 pm

    I think this is a common problem. There are a couple of approaches I use:

    1) This is my recommended approach. Use a viewmodel which encompasses only the properties that you want to be edited. This can then be bound back directly as you are currently trying to do. The problem with this approach is that you then need to copy the properties from and to your EF objects. If the naming is consistent you may be able to use a dumb reflection copier. If they are not, or you need to walk a graph to copy them back, then I tend to end up putting that custom logic into the viewmodel class. (Which makes it more than a pure view model – but nothing other than the viewmodel and the view needs to be aware of its existence.)

    2) Use modified binding. You can specify [Bind(Exclude=”this,that,theother”)] to stop certain properties being nulled out, and when the properties are scalar properties that you simply don’t want to have on screen, use Html.HiddenFor(x=>x.myprop)

    Another approach is

    3) Custom Binders. You can register your own custom binder and engineer whatever you need. This isn’t an approach I’ve used. but might work well.

    The reason 1) is a much better approach than 2) (IMHO) is that 2) exposes your entire model for update via HTML POST. The MVC binder will bind changes to anything that fits, so a well crafted POST can do some unexpected things: traversing relationships you hadn’t intended to expose and updating properties. The Viewmodel pattern on the other hand needs to have entities that only expose the fields the user interacts with so are safe to bind to.

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

Sidebar

Related Questions

I have a sort of plug-in model in which various complex user controls are
Well i have a complex form view model like this : public class TransactionFormViewModel
I have a 'Complex' model which hasMany Unit. My model associations are correct, everything
I have a class which inherits QAbstractTableModel, and holds some complex structs in a
I have a complex django object, which has properties of other class types. This
I am using WCF and REST, and I have complex types, which are working
I have a complex .NET Remoting server app that provides a couple of services.
I have two complex (i.e. objects with string, int, double, List and other home
I have a complex WPF UserControl made of other ContentControl templates which contain sets
I have a complex form for a model Schedule that belongs to a parent

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.