Мне нужно иметь несколько так называемых «создавать» формы на мой взгляд. Мне нужен совет относительно того, как это сделать. Моя форма в основном позволяет пользователю создавать пассажирские реквизиты/книги для нескольких пассажиров в зависимости от числа, которое они выбрали из выпадающего списка. Используя javascript, больше div будет отображаться, чтобы удовлетворить их выбор, максимум до 3. Как бы я хотел создать эти пассажиры на моей модели с помощью одной кнопки отправки? Как мне собрать эти ценности? Есть в общей сложности 3 дивы, и более пассажирских деталей пользователь хочет забронировать для, тем больше дивы являются shown.My вид в настоящее время выглядит следующим образом:Как создать «Создать представление» с несколькими динамическими полями?
<h2>Booking</h2>
<div class="editor-label">
<%=Html.Label("Select number of passengers") %>
</div>
<div class="editor-field">
<%=Html.DropDownList("PassengerNumber", new List<SelectListItem>
{
new SelectListItem{Text="1", Value="1"},
new SelectListItem{Text="2", Value="2"},
new SelectListItem{Text="3", Value="3"}
})%>
</div>
<% using (Html.BeginForm()) {%>
<%= Html.ValidationSummary(true) %>
<fieldset>
<legend>Fields</legend>
<div id="div1">
<h2>Passenger Details 1</h2>
<div class="editor-label">
<%= Html.LabelFor(model => model.flight_number) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.flight_number, ViewData["Flight_Number"]) %>
<%= Html.ValidationMessageFor(model => model.flight_number) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.title) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.title) %>
<%= Html.ValidationMessageFor(model => model.title) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.first_name) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.first_name) %>
<%= Html.ValidationMessageFor(model => model.first_name) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.last_name) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.last_name) %>
<%= Html.ValidationMessageFor(model => model.last_name) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.date_of_birth) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.date_of_birth) %>
<%= Html.ValidationMessageFor(model => model.date_of_birth) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.passport_number) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.passport_number) %>
<%= Html.ValidationMessageFor(model => model.passport_number) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.address) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.address) %>
<%= Html.ValidationMessageFor(model => model.address) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.phone) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.phone) %>
<%= Html.ValidationMessageFor(model => model.phone) %>
</div>
</div>
<br />
<div id="div2">
<h2>Passenger Details 2</h2>
<div class="editor-label">
<%= Html.LabelFor(model => model.flight_number) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.flight_number, ViewData["Flight_Number"]) %>
<%= Html.ValidationMessageFor(model => model.flight_number) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.title) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.title) %>
<%= Html.ValidationMessageFor(model => model.title) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.first_name) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.first_name) %>
<%= Html.ValidationMessageFor(model => model.first_name) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.last_name) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.last_name) %>
<%= Html.ValidationMessageFor(model => model.last_name) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.date_of_birth) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.date_of_birth) %>
<%= Html.ValidationMessageFor(model => model.date_of_birth) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.passport_number) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.passport_number) %>
<%= Html.ValidationMessageFor(model => model.passport_number) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.address) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.address) %>
<%= Html.ValidationMessageFor(model => model.address) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.phone) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.phone) %>
<%= Html.ValidationMessageFor(model => model.phone) %>
</div>
</div>
<br />
<div id="div3">
<h2>Passenger Details 3</h2>
<div class="editor-label">
<%= Html.LabelFor(model => model.flight_number) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.flight_number, ViewData["Flight_Number"]) %>
<%= Html.ValidationMessageFor(model => model.flight_number) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.title) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.title) %>
<%= Html.ValidationMessageFor(model => model.title) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.first_name) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.first_name) %>
<%= Html.ValidationMessageFor(model => model.first_name) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.last_name) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.last_name) %>
<%= Html.ValidationMessageFor(model => model.last_name) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.date_of_birth) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.date_of_birth) %>
<%= Html.ValidationMessageFor(model => model.date_of_birth) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.passport_number) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.passport_number) %>
<%= Html.ValidationMessageFor(model => model.passport_number) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.address) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.address) %>
<%= Html.ValidationMessageFor(model => model.address) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.phone) %>
</div>
<div class="editor-field">
<%= Html.TextBoxFor(model => model.phone) %>
<%= Html.ValidationMessageFor(model => model.phone) %>
</div>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
<div>
<%= Html.ActionLink("Back to List", "Index") %>
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#div2").hide();
$("#div3").hide();
});
$("#PassengerNumber").change(function() {
if ($("#PassengerNumber").val() == "1") {
$("#div2").hide();
$("#div3").hide();
}
if ($("#PassengerNumber").val() == "2") {
$("#div2").show();
$("#div3").hide();
}
if ($("#PassengerNumber").val() == "3") {
$("#div2").show();
$("#div3").show();
}
});
</script>