You can link AccountModel and AccountDetailModel, and then use AccountModel:
public AccountModel
{
public int Id { get; set; }
public string Name { get; set; }
public IList<AccountDetailModel> Details { get; set; }
}
public AccountDetailModel
{
public int Id { get; set; }
public string Description { get; set; }
}
In the view:
@model AccountModel
. . .
@Html.HiddenFor(m => m.Id)
@Html.TextboxFor(m => m.Name)
@for (int i = 0; i < Model.Details.Count; i++)
{
@Html.HiddenFor(m => m.Details[i].Id)
@Html.TextboxFor(m => m.Details[i].Description)
}
In the action some code like this:
[HttpPost]
public ActionView Insert(AccountModel model)
{
using (var dbContext = new DbContext())
{
var account = new Account();
account.Id = model.Id;
account.Name = model.Name;
account.Details = new List<AccountDetail>();
dbContext.AddObject(account);
foreach (var modelDetail in model.Details)
{
var accountDetail = new AccountDetail();
accountDetail.Id = modelDetail.Id;
accountDetail.Description = modelDetail.Description;
account.Details.Add(accountDetail);
dbContext.AddObject(accountDetail);
}
dbContext.SaveChanges();
}
}
If you want to update the record, you'll need some code to check, if the related detail record should be inserted or updated.