How to find properties are not modified or change?

Go To


I have viewmodel which i am binding with my view call "EditProfile". Now once the user click on the "EditProfile" link from the menu bar I load all the profile information by calling get restful service and user can see his/her profile.

User can change any field they want but I want to post only fields that are changed by User.

I know how to compare two properties but don't know how to pull only modified properties from the viewmodel. Have anybody arrived to this situation before?

Properties in my viewmodel are:

 public class UserViewModel
  public string FirstName { get; set; } 
  public string LastName { get; set; }
  public string Email { get; set; }
  public string Profession { get; set; }
2012-04-03 19:47
by updev


In the past I implemented INotifyPropertyChanged for the ViewModel. And I logged which property's changed after the PropertyChanged event fired.

2012-04-03 19:52
by Khan
do you have the code sample for this scenario as you have done it before - updev 2012-04-03 21:29


Why not take an alternative approach - post everything (so the model is available) and simply have "IsDirty" properties on your objects that are smart enough to submit only changes to the database (like the entity framework does by default)

You can simply form your own jQuery .post() parameters, but unless you have a ton of data - why? It makes for a difficult to read view model (how do you know what is posted under what scenarios) so the typical approach is to post separate view models or post everything which in my opinion for basic forms is easier.

2012-04-03 20:20
by Adam Tuliper - MSFT