使用 Blazor 处理数据注释
Working with Data Annotations with Blazor
<EditForm Model="CurrentCustomerSubmission" OnValidSubmit="ToSubmissionPage">
<DataAnnotationsValidator/>
<div class="wrap-login100 p-l-50 p-r-50 p-t-72 p-b-50">
<form class="login100-form validate-form">
<span class="login100-form-title p-b-59">
Sign Up
</span>
<div class="wrap-input100 validate-input" data-validate="First Name is required">
<span class="label-input100">First Name</span>
<input class="input100" type="text" name="firstName" placeholder="First Name..." @bind-value="@CurrentCustomerSubmission.customerFirstName" />
<span class="focus-input100"></span>
</div>
来自我的模型class
public class CustomerModel
{
[Required]
[StringLength(20, ErrorMessage = "First Name too long (20 letter limit)")]
当我在我的表单上单击提交时,没有进行验证并且表单刷新并且所有数据都丢失了。
EditForm 组件呈现为 Html 表单,但是您的标记包含另一个表单标签。我想问题出在这里...您不应该在表单中嵌入表单...
<EditForm Model="CurrentCustomerSubmission" OnValidSubmit="ToSubmissionPage">
<DataAnnotationsValidator/>
<div class="wrap-login100 p-l-50 p-r-50 p-t-72 p-b-50">
<form class="login100-form validate-form">
<span class="login100-form-title p-b-59">
Sign Up
</span>
<div class="wrap-input100 validate-input" data-validate="First Name is required">
<span class="label-input100">First Name</span>
<input class="input100" type="text" name="firstName" placeholder="First Name..." @bind-value="@CurrentCustomerSubmission.customerFirstName" />
<span class="focus-input100"></span>
</div>
来自我的模型class
public class CustomerModel
{
[Required]
[StringLength(20, ErrorMessage = "First Name too long (20 letter limit)")]
当我在我的表单上单击提交时,没有进行验证并且表单刷新并且所有数据都丢失了。
EditForm 组件呈现为 Html 表单,但是您的标记包含另一个表单标签。我想问题出在这里...您不应该在表单中嵌入表单...