tags:

views:

25

answers:

2

My viewmodel has a property called Recipient. That has a Property called MobileNumber

I'm trying this in MVC 2:

UpdateModel(viewmodel, new[] { "Recipient_MobileNumber" }); // I  expected this to work

I also tried "Recipient.MobileNumber"

A: 

Something like that I suppose:

public ActionResult Edit(int id /* id of recipient? */, FormCollection formValues)
{
    var viewmodel = GetViewModel(id);
    viewmodel.Recipient.ModileNumber = formValues["Recipient.MobileNumber"];
}
BritishDeveloper
+1  A: 

Try:

UpdateModel(viewmodel.Recipient, new[] { "MobileNumber" });

Your problem is your using the string[] includes as view data expressions which would hypothetically hop around the object graph to model bind what you need.

UpdateModel doesn't work that way. Those strings are simply used as filters over properties.

jfar
I had to add a prefix, but this got me on the right track to this:UpdateModel(viewmodel.Recipient, "Recipient", new[] { "MobileNumber" });
My Other Me
Ps. Thanks for the explanation. It all perfect sense once I read your explanation.
My Other Me