asp.net-core - 如果 mvc 视图中的验证失败,如何添加链接元素以及验证消息
问题描述
我有要求,如果电子邮件字段验证(如电子邮件)已经在使用时,它会显示验证消息电子邮件现在已经连同此验证消息一起使用我想附加登录链接我该怎么做
<div>
<input asp-for="Email" type="text" placeholder="Email" class="form-control" />
</div>
<span asp-validation-for="Email" id="err" class="text-danger"></span>
<a asp-area="" asp-controller="Account" asp-action="Login" asp-route-aname="indiaRegion">login</a>
Any Help That Grate For Me How Can I append The Link At Time Of email Validation Fail I have Remote Email Verification For Already In Use
解决方案
尝试使用远程验证并<a>
在验证消息中添加标签。检查以下代码:
用户视图模型:
[Remote(action: "VerifyEmail", controller: "Home")]
public string Email { get; set; }
视图中的代码:
<div class="form-group">
<label asp-for="Email" class="control-label"></label>
<input asp-for="Email" class="form-control" />
<span asp-validation-for="Email" class="text-danger"></span>
</div>
控制器中的代码:
[AcceptVerbs("GET", "POST")]
public IActionResult VerifyEmail(string email)
{
//Generate the login url:
string loginurl = string.Format("{0}://{1}/{2}", Request.Scheme, Request.Host, "Identity/Account/Login");
if (_userService.VerifyEmail(email))
{
return Json($"Email {email} is already in use, click the <a href='" + loginurl + "'> here </a> to login.");
}
return Json(true);
}
测试截图:
推荐阅读
- firebase - 如何配置我的 Google 身份平台以强制执行“每个电子邮件地址一个帐户”规则而不自动链接凭据?
- mongodb - Jasper 报告 mongodb 连接不会关闭
- git - VS Code 命令托盘中的 Flutter 找不到 git
- c++ - 对于 C++ Random Access Iterator(向量迭代器),迭代器之间的差异是如何计算的?
- .net - 如何在多租户架构中使用 ASP.NET Core Identity 框架服务将用户添加到角色
- javascript - 从实时 XML 中提取数据并显示在传单网络地图中?
- go - why dash is used in condition Go templates
- sql - 调查问题的加权平均值
- javascript - 附加到每个代理的列表?
- outlook - Outlook 约会的上下文 Outlook 加载项