-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a demo to show how to display asp-validaiton-summary on field cha…
…nges.
- Loading branch information
davidliang2008
committed
Jul 31, 2020
1 parent
32087b9
commit c41c4a6
Showing
6 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/Presentation/DL.NetCore.EmptySolution.Web.UI/Controllers/UserController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace DL.NetCore.EmptySolution.Web.UI.Controllers | ||
{ | ||
public class UserController : Controller | ||
{ | ||
public IActionResult Invite() | ||
{ | ||
return View(); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Presentation/DL.NetCore.EmptySolution.Web.UI/Models/User/InviteUserViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.ComponentModel; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace DL.NetCore.EmptySolution.Web.UI.Models.User | ||
{ | ||
public class InviteUserViewModel | ||
{ | ||
[DisplayName("Email Address")] | ||
[Required(ErrorMessage = "Please provide the invitee's Email Address")] | ||
[EmailAddress(ErrorMessage = "Please provide a valid email address")] | ||
[StringLength(254, ErrorMessage = "Maximum email address length exceeded")] | ||
public string EmailAddress { get; set; } | ||
|
||
[DisplayName("Display Name")] | ||
[Required(ErrorMessage = "Please provide the invitee's display name")] | ||
public string DisplayName { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/Presentation/DL.NetCore.EmptySolution.Web.UI/Views/User/Invite.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
@model DL.NetCore.EmptySolution.Web.UI.Models.User.InviteUserViewModel | ||
@{ | ||
ViewBag.Title = "Invite User"; | ||
} | ||
|
||
<h2>Invite User</h2> | ||
<div class="row"> | ||
<div class="col-md-6"> | ||
<h5>Simple Way: reuse asp-message-for</h5> | ||
<form asp-area="" asp-controller="user" asp-action="invite" | ||
data-ajax="true" | ||
data-ajax-method="POST" | ||
data-ajax-begin="onBegin" | ||
data-ajax-complete="onComplete"> | ||
<div class="form-group"> | ||
<label asp-for="EmailAddress"></label> | ||
<input asp-for="EmailAddress" class="form-control" /> | ||
</div> | ||
<div class="form-group"> | ||
<label asp-for="DisplayName"></label> | ||
<input asp-for="DisplayName" class="form-control" /> | ||
</div> | ||
|
||
<div class="form-group clientside-validation-summary"> | ||
<span asp-validation-for="EmailAddress" class="text-danger"></span> | ||
<span asp-validation-for="DisplayName" class="text-danger"></span> | ||
</div> | ||
|
||
<button type="submit" class="btn btn-primary">Invite</button> | ||
</form> | ||
</div> | ||
</div> | ||
|
||
@section scripts { | ||
<script type="text/javascript"> | ||
$(function () { | ||
window.onBegin = function () { | ||
}; | ||
window.onComplete = function () { | ||
}; | ||
}); | ||
</script> | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Presentation/DL.NetCore.EmptySolution.Web.UI/assets/css/extra/_validations.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
.validation-summary-errors, | ||
.field-validation-error { | ||
font-size: .9rem; | ||
} | ||
|
||
.clientside-validation-summary { | ||
display: flex; | ||
flex-flow: column nowrap; | ||
|
||
.field-validation-error > span:before { | ||
content: "*"; | ||
padding-right: .3rem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters