本文へスキップ
Skillpedia
WebサイトとUI(フロントエンド)5.8k · #14562

collect-user-input

できること

このスキルは、Blazorのフォーム、検索ボックス、入力の画面を作る手助けをします。検証と送信の処理を含みます。Blazorのアプリにデータ入力の機能を加える.NETの開発者のためのものです。

使う場面

  • ✓Blazorのアプリで、フォーム、検索ボックス、フィルターのパネルが必要なとき。
  • ✓注釈や独自のルールを使って、フォームに検証を付けたいとき。
  • ✓Blazorのページで、ファイルのアップロードやその場での編集がほしいとき。

スキルのリンク

https://github.com/dotnet/skills/blob/main/plugins/dotnet-blazor/skills/collect-user-input/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/dotnet/skills/blob/main/plugins/dotnet-blazor/skills/collect-user-input/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“名前とメールアドレスを検証し、ユーザーをデータベースに保存する、Blazorのサインアップフォームを追加してください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

エージェントはプロジェクトのインタラクティブの設定を読み、そのモードに合った方法でフォームを作り、検証を加えて、送信の操作を処理します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

Collect User Input

Step 1 — Read the Project's AGENTS.md

Check AGENTS.md for Interactivity Mode and Interactivity Scope. This determines which form patterns apply:

Mode Form mechanism
None (Static SSR) EditForm with FormName + [SupplyParameterFromForm]. No @bind, no @onchange.
Server EditForm with @bind-Value. Full interactivity — real-time validation, dynamic UI.
WebAssembly Same as Server, but validators needing server data must call APIs.
Auto Same as WebAssembly — code must work in both browser and server.
Scope Impact
Global All forms are interactive. FormName only needed when explicitly opting a page to static SSR.
Per-page Forms in static pages use FormName + [SupplyParameterFromForm]. Forms in @rendermode pages use @bind-Value.

EditForm Setup

EditForm requires either Model or EditContext — never both.

Model-based (default)

<EditForm Model="Employee" OnValidSubmit="HandleSubmit" FormName="employee">
    <DataAnnotationsValidator />
    <ValidationSummary />

    <label>
        Name: <InputText @bind-Value="Employee!.Name" />
        <ValidationMessage For="() => Employee!.Name" />
    </label>

    <button type="submit">Save</button>
</EditForm>

@code {
    [SupplyParameterFromForm]
    private EmployeeModel? Employee { get; set; }

    protected override void OnInitialized() => Employee ??= new();

    private async Task HandleSubmit()
    {
        // Save Employee
    }
}

This single pattern works in both SSR and interactive modes:

  • In SSR: FormName identifies the form, [SupplyParameterFromForm] binds POST data, ??= initializes on GET.
  • In interactive: @bind-Value provides two-way binding, [SupplyParameterFromForm] is ignored, FormName is harmless.

EditContext-based (advanced)

Use when you need programmatic field tracking, dynamic validation rules, or manual EditContext.Validate() calls:

private EditContext? editContext;
private EmployeeModel model = new();

protected override void OnInitialized()
{
    editContext = new EditContext(model);
}
<EditForm EditContext="editContext" OnValidSubmit="HandleSubmit" FormName="employee">

Submit Handlers

Handler Fires when Use when
OnValidSubmit Validation passes Standard forms with DataAnnotationsValidator
OnInvalidSubmit Validation fails Need custom handling for invalid state
OnSubmit Always — validation is manual Using EditContext.Validate() yourself

OnSubmit cannot combine with OnValidSubmit/OnInvalidSubmit.

Built-in Input Components

Component Binds to Notes
InputText string Renders <input type="text">
InputTextArea string Renders <textarea>
InputNumber<T> int, double, decimal Renders <input type="number">
InputDate<T> DateTime, DateOnly, DateTimeOffset Renders <input type="date">
InputCheckbox bool Renders <input type="checkbox">
InputSelect<T> string, enums, numeric types Renders <select>
InputRadioGroup<T> string, enums, numeric types Wraps InputRadio<T> children
InputFile IBrowserFile File upload — interactive modes only

All input components use @bind-Value for binding. Always wrap text in a <label> or use id/for attributes for accessibility.

InputSelect with enum values

<InputSelect @bind-Value="Model!.Status">
    <option value="">-- Select --</option>
    @foreach (var value in Enum.GetValues<OrderStatus>())
    {
        <option value="@value">@value</option>
    }
</InputSelect>

InputRadioGroup

<InputRadioGroup @bind-Value="Model!.Priority">
    @foreach (var p in Enum.GetValues<Priority>())
    {
        <label>
            <InputRadio Value="p" /> @p
        </label>
    }
</InputRadioGroup>

Validation

Data annotations

Define validation rules on the model:

public class EmployeeModel
{
    [Required, StringLength(100)]
    public string? Name { get; set; }

    [Required, EmailAddress]
    public string? Email { get; set; }

    [Range(18, 99)]
    public int Age { get; set; }

    [Required]
    public string? Department { get; set; }
}

Add <DataAnnotationsValidator /> inside EditForm — without it, annotatio

よくある質問

静的なページでも動きますか?

はい。インタラクティブなページと同様に、静的なサーバーのページのフォームの方法も扱います。

検証を加えますか?

はい。注釈に基づく検証と、独自の検証を扱います。

ファイルのアップロードも扱いますか?

はい。ファイルのアップロードは、対応する入力の種類の一つです。

詳細

作者による元の説明

Build forms, validate data, and react to user input in Blazor. USE FOR adding forms, search boxes, filter panels, inline editing, data-entry UI, file uploads, validation (annotations or custom), handling form submissions, and binding input controls. Covers EditForm, built-in input components, DataAnnotationsValidator, custom validation, SSR form patterns (SupplyParameterFromForm, FormName, AntiforgeryToken, Enhance), and @bind for simple interactive controls. DO NOT USE for project scaffolding (see create-blazor-project) or prerendering issues (see support-prerendering).

repo: dotnet/skills

人気

GitHubのスター
5.8k
ランキング
#14562
ライセンス
MIT
更新日
2026/11/2

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル