I've a Class say One
with following properties
class One
{
public int Id {get; set;}
public string Name {get; set;}
public string Salary {get; set;}
public string Designation {get; set;}
}
Now I created a list of type One
like this in a ViewModel
public class OneViewModel
{
public OneViewModel(){
lstOne = new List<One>();
}
List<One> lstOne {get;set;}
public int UserId {get;set;}
}
and added few objects to the list in ActionResult and passed it in model.
public ActionResult Index()
{
OneViewModel model = new OneViewModel();
model.lstOne.Add(new One{Id=1,Name="Sam",Salary="5000", Designation="Manager" });
model.lstOne.Add(new One{Id=2,Name="Akash",Salary="6000", Designation="Manager" });
model.lstOne.Add(new One{Id=3,Name="Sid",Salary="7000", Designation="Manager" });
return View(model);
}
Now when the post method is called I want to find out which objects were deleted or added in lstOne
and which properties were changed of a given object in lstOne
.
[HttpPost]
public ActionResult Index(OneViewModel model)
{
//what to do here, any ideas
}
I don't want to use an old approach of iterating through list and comparing objects and properties, is there any other way around. I saw ObservableCollection
and NotifyCollectionChangedEventArgs
on MSDN site, however, I was not able to get the right approach for implementing it in order to resolve my query.