I want to create A form where related data from credit and debit is also added in create action of journal.
I have three tables with code.
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; }
}
Below is the form code
@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>
}
Now the problem is how can i bind the data in create action to Credits and Debits
public ActionResult Create([Journal journal, ICollection<Credit> Credits, Icollection<Debits> Debits)