I have a partial view that generates a row of controls based on the selection from a dropdown. For example if the user selects 2 from the dropdown my for loop generates 2 rows of fields for them to fill out.
@for (int i = 0; i < 3; i++)
{
<div class="form-group col-md-3 col-sm-12">
Draw Number
@Html.TextBoxFor(x => x.DrawSchedule.drawNumber, new { @class= "form-control input-sm" })
</div>
<div class="form-group col-md-3 col-sm-12">
Draw Amount
@Html.TextBoxFor(x => x.DrawSchedule.drawAmount, new { @class = "form-control input-sm" })
</div>
<div class="form-group col-md-3 col-sm-12">
Draw Date
@Html.TextBoxFor(x => x.DrawSchedule.drawDate, new { @class = "form-control input-sm" })
</div>
<div class="clearfix"></div>
}
I then have my repository to save to the db.
public void SaveContract(ProjectViewModel project, tblPMContract contract, tblDraw draws)
{
tblPMContract dbEntry = repository.tblPMContracts.Add(contract);
{
dbEntry.penaltyAmount = project.ProjectContract.penaltyAmount;
dbEntry.estimateID = project.ProjectContract.estimateID;
dbEntry.requestID = project.ContractorEstimate.requestID;
}
tblDraw dbEntry2 = repository.tblDraws.Add(draws);
{
dbEntry2.drawNumber = project.DrawSchedule.drawNumber;
dbEntry2.drawAmount = project.DrawSchedule.drawAmount;
}
repository.SaveChanges();
}
I am not sure how to loop through a save to the database. If there is only 1 row of controls not a problem, but when there is more than 1 row it only saves the first row.