-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from haacked/haacked/add-select-demo
Add Demo of select input and validation summary
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
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,26 @@ | ||
@page | ||
@model DemoWeb.Pages.Demos.SelectInput | ||
@{ | ||
Layout = "Shared/_Layout"; | ||
} | ||
|
||
<div asp-validation-summary="All"> | ||
<span>Please correct the following errors</span> | ||
</div> | ||
|
||
<fieldset> | ||
<legend>Required Select input with validation summary.</legend> | ||
<form method="post"> | ||
<div class="form-field"> | ||
<label asp-for="Animal"></label> | ||
<select asp-for="Animal" asp-items="Model.Animals"></select> | ||
<span asp-validation-for="Animal"></span> | ||
</div> | ||
<div class="form-field"> | ||
<label asp-for="AnotherRequiredField"></label> | ||
<input asp-for="AnotherRequiredField" /> | ||
<span asp-validation-for="AnotherRequiredField"></span> | ||
</div> | ||
<input type="submit" value="Submit"/> | ||
</form> | ||
</fieldset> |
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,25 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.AspNetCore.Mvc.Rendering; | ||
|
||
namespace DemoWeb.Pages.Demos; | ||
|
||
public class SelectInput : PageModel | ||
{ | ||
[BindProperty] | ||
[Required] | ||
public string? Animal { get; set; } | ||
|
||
[BindProperty] | ||
[Required] | ||
public string? AnotherRequiredField { get; set; } | ||
|
||
public IReadOnlyList<SelectListItem> Animals => new List<SelectListItem> | ||
{ | ||
new("None", ""), | ||
new("Dog", "Dog"), | ||
new("Cat", "Cat"), | ||
new("Fish", "Fish"), | ||
}; | ||
} |
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