开发者

How do I make only one property of a model to be updated

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

I'm trying this in MVC 2:

UpdateModel(v开发者_StackOverflow社区iewmodel, new[] { "Recipient_MobileNumber" }); // I  expected this to work

I also tried "Recipient.MobileNumber"


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.


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"];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜