レジスタ ビューのすべてのフィールドで同じモデル エラー メッセージが表示されます。Register Post メソッドのコードは次のとおりです。
[CaptchaMvc.Attributes.CaptchaVerify("Captcha is not valid")]
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Register(RegisterRequest model)
{
if (ModelState.IsValid)
{
if (Membership_BAL.UsernameExist(model.UserName.Username))
{
ModelState.AddModelError("CustomError", "Usename is taken");
return View();
}
if (Membership_BAL.EmailExist(model.EmailAddress.EmailAddress))
{
ModelState.AddModelError("CustomError", "Email Address is taken");
return View();
}
if (
!Membership_BAL.CamparaEmailAddress(model.EmailAddress.EmailAddress,
model.EmailAddress.ComfirmEmailAddress))
{
ModelState.AddModelError("CustomError", "Email Address must match");
return View();
}
Membership_BAL.Register(model);
// TODO: Redirect use to profile page
return RedirectToAction("Index", "Home");
}
TempData["Message"] = "Error: captcha is not valid.";
return View();
}
これがビューです
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<fieldset>
<legend> Register Form</legend>
<ol>
<li>
@Html.LabelFor(m => Model.UserName.Username)
@Html.EditorFor(m => Model.UserName.Username)
@Html.ValidationSummary()
</li>
<li>
@Html.LabelFor(m => Model.FirstName)
@Html.EditorFor(m => Model.FirstName)
</li>
<li>
@Html.LabelFor(m => Model.LastName)
@Html.EditorFor(m => Model.LastName)
</li>
<li>
@Html.LabelFor(m => Model.EmailAddress.EmailAddress)
@Html.EditorFor(m => Model.EmailAddress.EmailAddress)
@Html.ValidationSummary()
</li>
<li>
@Html.LabelFor(m => Model.EmailAddress.ComfirmEmailAddress)
@Html.EditorFor(m => Model.EmailAddress.ComfirmEmailAddress)
@Html.ValidationSummary()
</li>
<li>
@Html.MathCaptcha()
@TempData["Message"]
</li>
</ol>
<input type="submit" value="Register">
</fieldset>
}