I think the problem is due to the Name prefix on the properties. I think you'll need to update it as two models and specify the prefix for the second one. Note that I've removed the FormCollection from the parameters and used the signature of UpdateModel that relies on the built-in value provider and specifies a whitelist of properties to consider public ActionResult Save( int id ) { Contact contact = db.Contacts.
Where( c => c. Id == id ) .SingleOrDefault(); UpdateModel(contact, new string { "Email" } ); string whitelist = new string { "Forename", "Surname" }; UpdateModel( contact. Name, "Name", whitelist ); }.
I think the problem is due to the Name prefix on the properties. I think you'll need to update it as two models and specify the prefix for the second one. Note that I've removed the FormCollection from the parameters and used the signature of UpdateModel that relies on the built-in value provider and specifies a whitelist of properties to consider.
Public ActionResult Save( int id ) { Contact contact = db.Contacts. Where( c => c. Id == id ) .SingleOrDefault(); UpdateModel(contact, new string { "Email" } ); string whitelist = new string { "Forename", "Surname" }; UpdateModel( contact.Name, "Name", whitelist ); }.
This works great, Thanks tvanfosson. – Allen Feb 27 '09 at 13:14.
Thats very interesting because if you had done public ActionResult Save( int id, Contact contact ) { //contact here would contain the nested values. } I'm using this with great success. I suppose then you could somehow sync the two Contact objects together.
I would have thought that the UpdateModel and the binding to the parameter use the same call behind the scenes. Note: haven't tried to reproduce your issue.
I'm wanting to get some binding working in my mvc application. I find nested properties are not automatically bound by the default model binder in the RC1 release of asp.net mvc. The Email property is successfully bound but not the Name.
Forename or Name. Can anyone tell if this should work using the default model binder and I'm doing something wrong or if it doesn't work and I need to roll my own code for binding nested properties on model objects?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.