Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Pages/Demos/SelectInput.cshtml
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>
25 changes: 25 additions & 0 deletions Pages/Demos/SelectInput.cshtml.cs
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"),
};
}
1 change: 1 addition & 0 deletions Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<li><a asp-page="Demos/Checkboxes">Checkboxes and Radio Buttons</a></li>
<li><a asp-page="Demos/SubmitButton">Submit Button</a></li>
<li><a asp-page="Demos/RemovedInputs">Removed Inputs</a></li>
<li><a asp-page="Demos/SelectInput">Select Input and Validation Summary</a></li>
</ul>

@if (Model.StatusMessage != null) {
Expand Down