Я использую страницы Razor для формы регистрации. Я использую привязку модели для привязки формы к свойствам модели страницы. Я использую аннотацию данных Compare (nameof ()) для проверки полей пароля. Когда два поля пароля совпадают, сравнение по-прежнему не удается, и ModelState.IsValid возвращает false. Сводка проверки гласит: «Не удалось найти свойство с именем txtPassword»
Вот мой код формы:
<form method="post">
<div class="col-12">
<label asp-for="ddlInstitution"></label>
<select asp-for="ddlInstitution" asp-items="@((List<SelectListItem>)Model.Institutions)">
</select>
<div>If your institution is not listed please email the Principal Investigator to request that
it be added.</div>
</div>
<p />
<div class="row gtr-uniform">
<div class="col-6 col-12-small">
<label asp-for="txtFirstName"></label>
<input asp-for="txtFirstName" class="form-control form-control-sm" />
<span asp-validation-for="txtFirstName" class="text-danger" style="color: red"></span>
</div>
<div class="col-6 col-12-small">
<label asp-for="txtLastName"></label>
<input asp-for="txtLastName" class="form-control form-control-sm" />
<span asp-validation-for="txtLastName" class="text-danger" style="color: red"></span>
</div>
</div>
<p/>
<div class="col-12">
<label asp-for="txtEmailAddress"></label>
<input asp-for="txtEmailAddress" class="form-control form-control-sm" />
<span asp-validation-for="txtEmailAddress" class="text-danger" style="color: red"></span>
</div>
</p>
<div class="row gtr-uniform">
<div class="col-6 col-12-small">
<label asp-for="txtTitle"></label>
<input asp-for="txtTitle" class="form-control form-control-sm" />
<span asp-validation-for="txtTitle" class="text-danger" style="color: red"></span>
</div>
<div class="col-6 col-12-small">
<label asp-for="txtDepartment"></label>
<input asp-for="txtDepartment" class="form-control form-control-sm" />
<span asp-validation-for="txtDepartment" class="text-danger" style="color: red"></span>
</div>
</div>
</p>
<div class="row gtr-uniform">
<div class="col-6 col-12-small">
<label asp-for="txtPassword"></label>
<input name="txtPassword" id="txtPassword" type="password" asp-for="txtPassword" class="form-control form-control-sm" />
<span asp-validation-for="txtPassword" class="text-danger" style="color: red"></span>
</div>
<div class="col-6 col-12-small">
<label asp-for="txtConfirmPassword"></label>
<input type="password" asp-for="txtConfirmPassword" class="form-control form-control-sm" />
<span asp-validation-for="txtConfirmPassword" class="text-danger" style="color: red"></span>
</div>
</div>
<p/>
<div class="col-12">
<input type="submit" class="button fit"/>
</div>
Вот моя привязка PageModel. Все кажется правильным.
[BindProperty, Required, Display(Name = "Institution Name")]
public string ddlInstitution {get; set;}
[BindProperty, Required, Display(Name="First Name")]
public string txtFirstName { get; set; }
[BindProperty, Required, Display(Name = "Last Name")]
public string txtLastName { get; set; }
[BindProperty, Required, EmailAddress, Display(Name = "Email Address")]
public string txtEmailAddress { get; set; }
public List<SelectListItem> Institutions { get; set; }
[BindProperty, Required, MinLength(2), Display(Name = "Title")]
public string txtTitle { get; set; }
[BindProperty, Required, MinLength(3), Display(Name = "Department")]
public string txtDepartment { get; set; }
[BindProperty, Required, MinLength(8), MaxLength(16), Display(Name = "Password")]
public string txtPassword { get; set; }
[BindProperty, Required, MinLength(8), MaxLength(16), Compare(nameof(txtPassword), ErrorMessage = "Your passwords do not match."), Display(Name = "Confirm Password")]
public string txtConfirmPassword { get; set; }
public string Color {get; set;}
Сейчас я официально на стадии "выдернуть мои волосы". Все правильно. Я ценю любые советы, которые кто-либо может дать.