I have the following JSON when user clicks save
tasks : {
updated : [
{ Id : 123, SomeField1 : 'new value', SomeField2 : 'new value', SomeField3 : 'new value' },
{ Id : 125, SomeField2 : 'new value' },
{ Id : 127, SomeField1 : 'new value', SomeField4 : 'new value' },
{ Id : 129, SomeField2 : 'new value', SomeField3 : 'new value' },
{ ................ }
],
removed : [
{ Id : 345 },
{ Id : 847 }
]
}
on the MVC server side (C#), I have a ViewModel and .NET deserializes this back to my viewmodel object. in this example, This object has Id, SomeField1, SomeField2, SomeField3, SomeField4.
The problem I am having is that the client only sends the fields which were actually updated, so If the user never updated SomeField3 it wont be in the json and .NET for that array object will have a null as SomeeField3 ...
so i cant get record, update all the fields to what the viewmodel is and then call an update as it will set SomeField3 to null , which is not correct - there could be data in that field which the user just didn't touch in this case .. (in another case they may have deleted their text, which then the update would be valid..
I am not sure what is the best way to tackle this problem. Looking forward to your suggestions.