Skip to content

Commit

Permalink
Demo RemoteAttribute.AdditionalFields in Validation sample. (#14932)
Browse files Browse the repository at this point in the history
  • Loading branch information
serpent5 authored and Rick-Anderson committed Oct 8, 2019
1 parent cc24622 commit 74de68c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
Expand Up @@ -39,10 +39,10 @@ public IActionResult VerifyName(string firstName, string lastName)
{
if (!_userRepository.VerifyName(firstName, lastName))
{
return Json(data: $"A user named {firstName} {lastName} already exists.");
return Json($"A user named {firstName} {lastName} already exists.");
}

return Json(data: true);
return Json(true);
}
#endregion

Expand All @@ -65,6 +65,11 @@ public IActionResult CheckPhone()
}
#endregion

public IActionResult CheckName()
{
return View();
}

public IActionResult CheckAge()
{
return View();
Expand Down
Expand Up @@ -22,6 +22,7 @@
<a class="nav-link text-dark" asp-area="" asp-controller="Users" asp-action="CheckEmail">Check Email</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Users" asp-action="CheckPhone">Check Phone</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Users" asp-action="CheckAge">Check Age</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Users" asp-action="CheckName">Check Name</a>
</ul>
</div>
</div>
Expand Down
@@ -0,0 +1,39 @@
@model User
@{
ViewData["Title"] = "Check Name";
}

<h2>Check Name</h2>
<form asp-action="CheckName">
<div class="form-horizontal">
<h4>User Name</h4>
<hr />
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<ol>
<li>Enter a first name and last name. Validate accepts the name.</li>
<li>Enter a different first name and last name. Validate accepts the name.</li>
<li>Re-enter the first name and last name from the first step. Validation fails.</li>
</ol>
<label asp-for="FirstName" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="FirstName" class="form-control" />
<span asp-validation-for="FirstName" class="text-danger"></span>
</div>
<label asp-for="LastName" class="col-md-2 control-label"></label>
<div class="col-md-10">
<input asp-for="LastName" class="form-control" />
<span asp-validation-for="LastName" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="button" value="Validate" class="btn btn-default" />
</div>
</div>
</div>
</form>

@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}

0 comments on commit 74de68c

Please sign in to comment.