ASP.net MVC - Update Model on complex models
- by ludicco
Hi there, I'm struggling myself trying to get the contents of a form which is a complex model and then update the model with that complex model.
My account model has many individuals
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult OpenAnAccount(string area,[Bind(Exclude = "Id")]Account account, [Bind(Prefix="Account.Individuals")] EntitySet<Individual> individuals){
var db = new DB();
account.individuals = invdividuals;
db.Accounts.InsertOnSubmit(account);
db.SubmitChanges();
}
So it works nicely for adding new Records, but not for update them like:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult OpenAnAccount(string area,[Bind(Exclude = "Id")]Account account, [Bind(Prefix="Account.Individuals")] EntitySet<Individual> individuals){
var db = new DB();
var record = db.Accounts.Single(a => a.Reference == area);
account.individuals = invdividuals;
try{
UpdateModel(record, account); // I can't convert account ToValueProvider()
db.SubmitChanges();
}
catch{
return ... //Error Message
}
}
My problem is being how to use UpdateModel with the account model since it's not a FormCollection.
How can I convert it? How can I use ToValueProvider with a complex model?
I hope I was clear enough
Thanks a lot :)