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.