我希望能够使用 Blazor(服务器端渲染)渲染表单,但我没有得到正确的语法。
<EditForm Model="@Model" OnValidSubmit="@SubmitValidForm">
<FluentValidationValidator />
<ValidationSummary />
<p class="name">
Name: <InputText bind-Value="@Model.Name" placeholder="Name"/>
</p>
<button type="submit">Submit</button>
</EditForm>
@code {
Person Model = new Person();
void SubmitValidForm()
{
Console.WriteLine("OnValidSubmit");
}
}
和
public class Person : ComponentBase
{
[Required(ErrorMessage = "Enter a name")]
[StringLength(10, ErrorMessage = "That name is too long")]
public string Name { get; set; } = "asd";
[Range(0, 200, ErrorMessage = "Nobody is that old")]
public int AgeInYears { get; set; }
[Required]
[Range(typeof(bool), "true", "true", ErrorMessage = "Must accept terms")]
public bool AcceptsTerms { get; set; }
}
但我得到这个错误
Microsoft.AspNetCore.Components.Forms.InputText 需要“ValueExpression”参数的值。通常这是在使用“绑定值”时自动提供的。
一个人如何渲染页面并向服务器发送一个简单的帖子?