views:

22

answers:

1

I have a model that contains a List<PhoneNumber> property. I use TryUpdateModel in my update actions. Adding new numbers and changing existing numbers works fine. Removing existing numbers, however, works only if I don't try to remove everything. If I remove everything from the list, none of the items get deleted.

I realize that this is probably by design, but what's the recommended approach for dealing with this problem?

A: 

I'm currently going with this approach:

List<PhoneNumber> phoneNumbers = new List<PhoneNumber>();
TryUpdateModel<List<PhoneNumber>>(phoneNumbers, "Student.PhoneNumbers", form);

if (phoneNumbers.Count == 0)
{
    student.PhoneNumbers = phoneNumbers;
}
Ragesh