I have foreach loop which contains some data. What I want is if user click on add button, save the details to the database as well as empty input values and go to the next iteration of the foreach loop. Following is my code that I tried so far.
@model ModelLib.Models.PaymentDetails
@{
Layout = null;
var fullCount = Model.listRoomDetails.Max(x => x.FullCount);
}
<div class="row">
@Html.AntiForgeryToken()
<div class="row">
<div>You have to add <span id="passangerCount">@fullCount</span> Passanger details</div>
@foreach (var item in Model.listRoomDetails) {
<span>@item.RoomType RoomType Passanger Count : </span ><div id="@item.RoomType">@item.Count</div>
}
@foreach (var item in Model.listRoomDetails) {
<div class="row">
Room Type - <span id="existing_RoomType">@item.RoomType</span>
Room Category - <span id="existing_RoomCategory">@item.RoomCategory</span>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-info" style="background-color:#ffffff;">
<div class="panel-heading" id="payment_heading" style="border-style: double; text-align: center; background-color: #f59e6b; border-color: black; color: black; font-weight: bold;">Add Payment Details<i class="fa fa-chevron-circle-down" style="font-size: 24px; float: right; margin-right: -17px; margin-top: 6px;"></i></div>
<div class="panel-body" id="payment_body">
<div class="row">
<div class="col-sm-4">
<div class="col-sm-6">
@Html.LabelFor(model => model.TicketNumber, new { @class = "label_class" })
</div>
<div class="col-sm-6">
<div class="form-group">
@Html.TextBoxFor(model => model.TicketNumber, new { type = "text", maxlength = "13", @id = "ticketNumber", @class = "form-control", data_toggle = "tooltip", title = "Enter Ticket Name" })
</div>
</div>
</div>
<div class="col-sm-4">
<div class="col-sm-6">
@Html.LabelFor(model => model.PassangerName, new { @class = "label_class" })
</div>
<div class="col-sm-6">
@Html.TextBoxFor(model => model.PassangerName, new { @id = "passangerName", @class = "form-control", data_toggle = "tooltip", title = "Enter passanger Name" })
</div>
</div>
<div class="col-sm-4">
<div class="col-sm-6">
@Html.LabelFor(model => model.PassportNumber, new { @class = "label_class" })
</div>
<div class="col-sm-6">
@Html.TextBoxFor(model => model.PassportNumber, new { @id = "passportNumber", @class = "form-control", data_toggle = "tooltip", title = "Enter passport number", maxlength = 8 })
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<div class="col-sm-6">
@Html.LabelFor(model => model.PkgVal, new { @class = "label_class" })
</div>
<div class="col-sm-6">
<div class="form-group">
@Html.TextBoxFor(model => model.PkgVal, new { type = "number", @min = "0", @id = "pkgVal", data_toggle = "tooltip", title = "Enter valid pkg value", @class = "form-control" })
</div>
</div>
</div>
<div class="col-sm-4">
<div class="col-sm-6">
@Html.LabelFor(model => model.AirFare, new { @class = "label_class" })
</div>
<div class="col-sm-6">
@Html.TextBoxFor(model => model.AirFare, new { type = "number", @min = "0", @id = "airFare", data_toggle = "tooltip", title = "Enter valid airfare", @class = "form-control" })
</div>
</div>
<div class="col-sm-4">
<div class="col-sm-6">
@Html.LabelFor(model => model.Tax, new { @class = "label_class" })
</div>
<div class="col-sm-6">
@Html.TextBoxFor(model => model.Tax, new { type = "number", @min = "0", @id = "tax", data_toggle = "tooltip", title = "Enter valid tax", @class = "form-control" })
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<div class="col-sm-6">
@Html.LabelFor(model => model.DateChangeFee, new { @class = "label_class" })
</div>
<div class="col-sm-6">
@Html.TextBoxFor(model => model.DateChangeFee, new { type = "number", @min = "0", @id = "dateChangeFee", data_toggle = "tooltip", title = "Enter valid date change fee value", @class = "form-control" })
</div>
</div>
<div class="col-sm-4">
<div class="col-sm-6">
@Html.LabelFor(model => model.CommissionToAgent, new { @class = "label_class" })
</div>
<div class="col-sm-6">
@Html.TextBoxFor(model => model.CommissionToAgent, new { type = "number", @min = "0", @id = "commissionToAgent", data_toggle = "tooltip", title = "Enter valid commission to agent value", @class = "form-control" })
</div>
</div>
<div class="col-sm-4">
<div class="col-sm-6">
@Html.LabelFor(model => model.VMPDNumber, new { @class = "label_class" })
</div>
<div class="col-sm-6">
<div class="form-group">
@Html.TextBoxFor(model => model.VMPDNumber, new { type = "text", maxlength = "13", @id = "vmpdNumber", data_toggle = "tooltip", title = "Enter vmpd number", @class = "form-control" })
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<div class="col-sm-6">
@Html.LabelFor(model => model.EMDNumber, new { @class = "label_class", @style = "margin-top: -3px;" })
</div>
<div class="col-sm-6">
<div class="form-group">
@Html.TextBoxFor(model => model.EMDNumber, new { type = "text", maxlength = "13", @id = "emdNumber", data_toggle = "tooltip", title = "Enter emd number", @class = "form-control" })
</div>
</div>
</div>
<div class="col-sm-4">
<div class="col-sm-6">
@Html.LabelFor(model => model.RoomType, new { @class = "label_class", @style = "margin-top: -3px;" })
</div>
<div class="col-sm-6">
<div class="form-group">
@Html.TextBox(item.RoomType, new { type = "text", @id = "roomType", @class = "form-control" })
</div>
</div>
</div>
<div class="col-sm-4">
<div class="col-sm-6">
@Html.LabelFor(model => model.RoomCat, new { @class = "label_class", @style = "margin-top: -3px;" })
</div>
<div class="col-sm-6">
<div class="form-group">
@Html.TextBox(item.RoomCategory, new { type = "text", @id = "roomCat", @class = "form-control" })
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<p>
<input type="button" class="btn btn-info btn-add" name="PaymentDetails" id="PaymentDetails_btn" value="Add" data-url="@Url.Action("PaymentDetails", "EVoucher")" />
</p>
</div>
}
</div>
</div>
I can save the value to database when the user clicks on add button by using Ajax call. But How can I change the foreach loop value according the relevant iteration?
Any help will really appreciate. Thanks
Update - @Liam, I want to change @item.RoomType, @item.RoomCategory according to the foreach loop value. But I dont want to display all the inputs at one time. For ex if I have count 20, I only want to display one at a time. not all 20.