我想创建一个表单,其中来自信用卡和借记卡的相关数据也会添加到日记帐的创建操作中。
我有三张带代码的表。
public class Journal
{
public int ID { get; set; }
public DateTime journalDT { get; set; }
public decimal Amount { get; set; }
public virtual ICollection<Credit> Credits { get; set; }
public virtual ICollection<Debit> Debits { get; set; }
}
public class Credit
{
public int ID { get; set; }
public int JournalID { get; set; }
public int CodeID { get; set; }
public decimal Amount { get; set; }
public virtual Journal Journal { get; set; }
public virtual Code Code { get; set; }
}
public class Debit
{
public int ID { get; set; }
public int JournalID { get; set; }
public int CodeID { get; set; }
public decimal Amount { get; set; }
public virtual Journal Journal { get; set; }
public virtual Code Code { get; set; }
}
以下是表单代码
@using (Html.BeginForm())
{
Inputs for Jurnal Model......
<div class="row">
<div class="col-sm-6 text-center" style="border:1px solid red;">
Credit<br/>
<input type="text" id="Credit[0].CodeID" name="Credit[0].CodeID" value=1 />
<input type="text" id="Credit[0].Amount" name="Credit[0].Amount" value=23.00 />
<input type="text" id="Credit[1].CodeID" name="Credit[1].CodeID" value=2 />
<input type="text" id="Credit[1].Amount" name="Credit[1].Amount" value=123.00 />
<input type="text" id="Credit[2].CodeID" name="Credit[2].CodeID" value=3 />
<input type="text" id="Credit[2].Amount" name="Credit[2].Amount" value=223.00 />
</div>
<div class="col-sm-6 text-center" style="border:1px solid red;">
Debit
<input type="text" id="Debit[0].CodeID" name="Debit[0].CodeID" value=1 />
<input type="text" id="Debit[0].Amount" name="Debit[0].Amount" value=23.00 />
<input type="text" id="Debit[1].CodeID" name="Debit[1].CodeID" value=2 />
<input type="text" id="Debit[1].Amount" name="Debit[1].Amount" value=123.00 />
<input type="text" id="Debit[2].CodeID" name="Debit[2].CodeID" value=3 />
<input type="text" id="Debit[2].Amount" name="Debit[2].Amount" value=223.00 />
</div>
</div>
}
现在的问题是我如何将创建动作中的数据绑定到Credits和Debits
public ActionResult Create([Journal journal, ICollection<Credit> Credits, Icollection<Debits> Debits)