【发布时间】:2019-07-14 11:34:00
【问题描述】:
我希望能够使用 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”参数的值。通常这是在使用“绑定值”时自动提供的。
如何渲染页面并将简单的帖子发送到服务器?
【问题讨论】: