ASP.net MVC - Update Model on complex models
        Posted  
        
            by ludicco
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by ludicco
        
        
        
        Published on 2010-05-25T14:28:49Z
        Indexed on 
            2010/05/25
            14:31 UTC
        
        
        Read the original article
        Hit count: 586
        
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 :)
© Stack Overflow or respective owner