所以我有以下2个模型:
[Table("Company")]
public class Company {
public virtual List<UserAccount> Users {
get {
// I load my users here
}
}
}
[Table("UserAccount")]
public class UserAccount {
public string email { get; set; }
}
在我看来,我尝试编辑它:
@model MyXsite2013.Company
<table>
foreach (UserAccount ua in Model.Users) {
<tr class="noRowHover">
<td>
@Html.TextBoxFor(modelItem => ua.email)
</td>
</tr>
}
</table>
在回发时,我尝试保存:
public ActionResult Edit(Company companyModel) {
Company companyContext = database.Companies.Find(companyModel.ID);
database.Entry(companyContext).CurrentValues.SetValues(companyModel);
companyContext.IsActive = true;
database.SaveChanges();
}
当然,这不会将更改保存到用户,事实上,它甚至没有看到更改的到来。