Я новичок и в настоящее время использую Razor MVC 5, и я просто хочу спросить, как отобразить сообщение проверки, которое отображается в проиндексированном EditorFor. В настоящее время добавлены аннотации данных [Required (ErrorMessage = "Email Address is required")]
и [DataType(DataType.EmailAddress)]
, но они показывают подтверждение типа The Char field is required.
Вот мой набор кодов.
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "createform" }))
var cnt = 0;
{
<div class="form-horizontal">
@Html.ValidationSummary(true)
@if (Model.AttendeeCount > 0 && Model != null)
{
for (int i = 0; i < Model.AdultCount; i++)
{
cnt++;
<div id="div_@cnt">
<div>Adult @i</div>
<div class="form-group">
@Html.LabelFor(model => model.FirstName[cnt], new { @class = "control-label col-md-2" })
<div class="col-md-6">
@Html.EditorFor(model => model.FirstName[cnt], new { htmlAttributes = new { @class = "form-control", required = "required", title = "First Name is required" } })
@Html.ValidationMessageFor(model => model.FirstName[cnt], "", new { @class = "text-danger" })
</div>
</div>
....
<div class="form-group">
@Html.LabelFor(model => model.Email[cnt], htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-6">
@Html.EditorFor(model => model.Email[cnt], new { htmlAttributes = new { @class = "form-control", required = "required", title = "Email is required" } })
@Html.ValidationMessageFor(model => model.Email[cnt], "", new { @class = "text-danger" })
</div>
</div>
</div>
}
}
</div>
}
Пытался пройти проверку, добавив new { htmlAttributes = new { @class = "form-control", required = "required", title = "Email is required" } })
но безрезультатно все равно показывает ту же ошибку проверки The Char field is required.
Надеюсь, кто-то может помочь мне с этим
Редактировать: вот мой ModelView
[Required (ErrorMessage = "Last Name is required")]
[StringLength(50, ErrorMessage = "Last Name cannot be longer than 50 characters.")]
[Display(Name = "Last Name", Prompt = "Attendee Last Name")]
[DataType(DataType.Text)]
public string LastName { get; set; }
[Required(ErrorMessage = "First Name is required")]
[StringLength(50, ErrorMessage = "First Name cannot be longer than 50 characters.")]
[Display(Name = "First Name", Prompt = "Attendee First Name")]
[DataType(DataType.Text)]
public string FirstName { get; set; }
[Required(ErrorMessage = "PhoneNumber is required")]
[Display(Name = "Cell Phone")]
[DataType(DataType.PhoneNumber)]
public string CellPhone { get; set; }
[Required(ErrorMessage = "Email is required")]
[Display(Name = "Email")]
[DataType(DataType.EmailAddress)]
public string Email { get; set; }