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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:52:40+00:00 2026-06-09T06:52:40+00:00

I just ran into a little error in my MVC application. Administrators can edit

  • 0

I just ran into a little error in my MVC application.

Administrators can edit user profiles. Including the roles in which the user is.

So I have a ViewModel for “EditUser”:

public class EditUserViewModel
{
    public User User { get; set; }
    public IEnumerable<SelectListItem> PossibleRoles { get; set; }
    public int[] SelectedRoles { get; set; }
}

So, on my EditUser.cshtml page, I just run a @Html.EditorFor(Model => model.User) which generates the needed fields, according to the limitations of my MetaData class.

There, for example I have made annotations like this one:

    [ScaffoldColumn(false)]
    public string Password { get; set; }

The problem with this is, that when I post back my edit form, the values that are set as Scaffold false, are null. Which seems kind of logical because there is no edit box for those properties.

So when I save my entity it overwrites the values values with null. (E.g If I update a user’s name, and save, the user’s password is overwritten with null and EF throws an error)
Is there any way I could update the values automatically (according to the ones that I was able to edit (MetaDataClasses)?) ? Otherwise, if I copy them over to a freshly fetched entity from the Entity Framework, and I should change an annotation to Scaffold(false), I need to add a rule to the code where I copy the new values into the entity. And that just seems wrong.

Thanks in advance.

  • 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-09T06:52:42+00:00Added an answer on June 9, 2026 at 6:52 am

    EF works with whole entity and if you decide to not show some part of the entity you must also somewhere handle this when saving changes. You have multiple options:

    • Don’t use the entity if you don’t want to show all its data. Use special view model instead containing only data you want to show. Use that view model to collect changes and copy them to the entity (you can for example use AutoMapper for transforming entity to view model and vice versa).
    • Load the entity from database and update only fields you want to persist from your edit view model
    • Don’t set whole user entity as updated. Instead set manually every property you want to update.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just ran into a strange error: could not initialize a collection: [webServiceAction.aAssignedApplication#7] which
I'm using ASP.NET MVC 3, and just ran into a 'gotcha' using the DropDownListFor
I just finished a little 5000-line PHP application and are now going into testing
I just ran into something weird. I have two JSON arrays which holds different
I'm playing around a little with dividing up a MVC-site into several assemblies (ran
I just ran into the user-defined conversions to or from an interface are not
I just ran into this issue while making a GET request to a node.js
I just ran into a problem with the version of JAX-WS in JDK 1.6.0
I just ran into a SQL query with about 5 different columns in the
I just ran into something in Visual Studio 2010 RC that wasn't previously happening

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.