There are a couple of related questions, but I cannot find an answer that works.
Assuming I have the following models:
public class EditorViewModel
{
public Account Account {get;set;}
public string SomeSimpleStuff {get;set;}
}
public class Account
{
public string AccountName {get;set;}
public int MorePrimitivesFollow {get;set;}
}
and an extension ViewPage<EditorViewModel>view that does the following:
<%= Html.TextBoxFor(model => model.Account.AccountName)%>
<%= Html.ValidationMessageFor(model => model.Account.AccountName)%>
<%= Html.TextBoxFor(model => model.SomeSimpleStuff )%>
<%= Html.ValidationMessageFor(model => model.SomeSimpleStuff )%>
and my controller looks like this:
[HttpPost]
public virtual ActionResult Edit(EditorViewModel account)
{ }
How can I get DefaultModelBinder to properly bind my EditorViewModel? Without doing anything special, I get an empty instance of my EditorViewModel with all null or the default value.
The closest I came, UpdateModelmanually calling :
[HttpPost]
public virtual ActionResult Edit(EditorViewModel account)
{
account.Account = new Account();
UpdateModel(account.Account, "Account");
UpdateModel(account);
, UpdateModel account ( ViewModel), " ... ". , , .
?