У меня есть две группы радиокнопок на странице:
Phone 1: [ ] Home | [x] Work | [ ] Cell
Phone 2: [ ] Home | [ ] Work | [x] Cell
Когда вы видите страницу, я устанавливаю настройки по умолчанию для телефона 1, «Работа» и для телефона 2, «Сотовый».».Происходит то, что, когда пользователь отправляет и не вводит требуемое Имя, Имя И выбирает Дом (для Телефона 1) и Дом (Телефон 2) - когда страница обновляется, Телефон 1 является "Домой" иТелефон 2 - это «Сотовый».
Как это так?Телефон 2 должен быть "Домой", потому что это то, что я выбрал, прежде чем я получил сообщение об ошибке.Любая обратная связь с благодарностью!
Вот мнение:
@using (Html.BeginForm("create", "PetSittingRequest"))
{
<label class="labelleft" style="width: 100px">First Name:</label>
<div class="formfield" style="width: 205px">
@Html.TextBoxFor(model => model.ClientDetails[0].NameFirst, new { style = "width: 195px" })
@Html.ValidationMessageFor(model => model.ClientDetails[0].NameFirst, null )
</div>
// Phone #1 START
<label class="labelleft" style="width: 100px">Phone 1:</label>
<div class="formfield" style="width: 60px">
@Html.TextBoxFor(model => model.Phones[0].PhoneNumber, new { style = "width: 195px" })
@Html.ValidationMessageFor(model => model.Phones[0].PhoneNumber, null)
</div>
<div class="formfield" style="width: 60px"></div>
<div class="formfield" style="width: 95px"></div>
<div class="formfield" style="width: 60px">
@Html.RadioButtonFor(model => model.Phones[0].Location, "Home", new { @class="radiobtn" } ) Home
</div>
<div class="formfield" style="width: 60px">
@Html.RadioButtonFor(model => model.Phones[0].Location, "Work", new { @class="radiobtn", @checked = true } ) Work
</div>
<div class="formfield" style="width: 60px">
@Html.RadioButtonFor(model => model.Phones[0].Location, "Cell", new { @class="radiobtn" } ) Cell
</div>
// Phone #2 START
<label class="labelleft" style="width: 100px">Phone 2:</label>
<div class="formfield" style="width: 60px">
@Html.TextBoxFor(model => model.Phones[1].PhoneNumber, new { style = "width: 195px" })
@Html.ValidationMessageFor(model => model.Phones[1].PhoneNumber, null)
</div>
<div class="formfield" style="width: 60px"></div>
<div class="formfield" style="width: 95px"></div>
<div class="formfield" style="width: 60px">
@Html.RadioButtonFor(model => model.Phones[1].Location, "Home", new { @class="radiobtn" } ) Home
</div>
<div class="formfield" style="width: 60px">
@Html.RadioButtonFor(model => model.Phones[1].Location, "Work", new { @class="radiobtn" } ) Work
</div>
<div class="formfield" style="width: 60px">
@Html.RadioButtonFor(model => model.Phones[1].Location, "Cell", new { @class="radiobtn", @checked = true } ) Cell
</div>
}
Контроллер, который обрабатывает сообщение это:
[HttpPost]
public ActionResult Create(ClientUser x)
{
try
{
return View("Index", x);
}
catch
{
return View();
}
}
Вот модели:
public class ClientUser
{
public List<ClientDetail> ClientDetails { get; set; }
public List<Phone> Phones { get; set; }
}
public class ClientDetail
{
[Required(ErrorMessage="This field is required.")]
public string NameFirst { get; set; }
}
public class Phone
{
[Required(ErrorMessage="This field is required.")]
public string PhoneNumber { get; set; }
[Required(ErrorMessage="This field is required.")]
public string Location { get; set; }
}