ASP.net MVC - Update Model on complex models


ASP.net MVC - Update Model on complex models



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 :)

UPDATE

That's what I was looking for: http://goneale.com/2009/07/27/updating-multiple-child-objects-and-or-collections-in-asp-net-mvc-views/


asp.net mvc model item passed in to dictionary is of type List

1:

Why is my selected value showing up twice in a dropdownlist (asp.net mvc)
This scenario is not supported unless you have your Account type implement IValueProvider.. Interface arguments in ASP.NET MVC That would be any pretty strange MVC though. Auto generate grid using mvccontrib by passing datatable in ASP.net MVC 2 application The model binder should make sense of the HTTP request and translate this to your model not take bind your entities to your another entities.. WebMatrix, ASP.NET Razor, IIS Developer Express, SQL Server Compact Edition - What is Microsoft objective behind these new technologies? Upon further inspection I think you're looking for: http://msdn.microsoft.com/en-us/library/dd487246.aspx. Mocking and Stubbing Ajax Requests Try this:. using jquery datatable for server side processing with paging, filtering and search
 try{     db.Accounts.ApplyCurrentValues(record);      db.SubmitChanges();  } 
how do I use mvc data annotations in conjunction with auto generated linqtosql classes

98 out of 100 based on 43 user ratings 158 reviews

#