我有一个 asp.net 核心 MVC 项目。我有一个动作来检查用户提供的电子邮件是否存在?但它没有显示我的 ModelError 消息??有人可以帮忙吗?
这是我的行动:
[Route("/VerifyEmail")]
public IActionResult VerifyEmail()
{
return View();
}
[Route("/VerifyEmail")]
[HttpPost]
public IActionResult VerifyEmail(VerifyEmailViewModel verifyEmail)
{
if (!ModelState.IsValid)
{
return View(verifyEmail);
}
if (!_userService.IsExistEmail(verifyEmail.Email))
{
ModelState.AddModelError("Email", " ایمیل وارد شده معتبر نیست");
return View(verifyEmail);
}
var currentUser = _userService.GetUserByEmail(verifyEmail.Email);
return View("/Views/Account/SuccessEmail.cshtml", currentUser);
}
这是我的 Razore 视图:
@model GameShop.Data.Domain.ViewModels.VerifyEmailViewModel
<div class="row">
<div class="col-md-12">
<form action="/VerifyEmail" method="POST">
<div class="form-group">
<label asp-for="Email" class="control-label"></label>
<input asp-for="Email" class="form-group" />
<span asp-validation-for="Email" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="ارسال" class="btn btn-success" />
</div>
</form>
</div>
</div>
@section Scripts{
@{await Html.RenderPartialAsync("_ValidationScriptsPartial.cshtml");}
}