Blazor 文档的表单验证示例在组件中有一个提交按钮EditForm
组件:
<EditForm Model="@starship" > OnValidSubmit="@HandleValidSubmit"> <DataAnnotationsValidator /> <ValidationSummary /> <p> <label for="identifier">Identifier: </label> <InputText id="identifier" bind Value="@starship.Identifier" /> </p> Snip.... <button type="submit">Submit</button> Snip... </EditForm>
无论如何将提交按钮放置在标签之外EditForm
并且仍然让它“本机”触发该EditForm
组件的提交而不诉诸使用JavaScript?
即代码看起来像这样:
<!-- Want this button to submit the form in the EditForm tags-->
<button type="submit">Submit</button>
Snip...
<EditForm Model="@starship" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<p>
<label for="identifier">Identifier: </label>
<InputText id="identifier" bind-Value="@starship.Identifier" />
</p>
</EditForm>