我希望能够使用Blazor (服务器端渲染)呈现表单
我尝试了大部分的教程,但我看不出我做错了什么。我将.net核心更新到最新版本SDK3.0.100-preview6-012264
<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 requires a value for the 'ValueExpression' parameter. Normally this is provided automatically when using 'bind-Value'.'
我想呈现页面并向服务器发送一个简单的post
有人能帮帮忙吗?
发布于 2019-10-01 09:10:06
对我来说,这是因为我使用的是@bind-value
。
v
是大写的。使用@bind-Value
发布于 2019-07-15 08:53:00
我今晚也在为同样的事情苦苦挣扎。我在"bind-Value“之前省略了"@”符号(我可以称它为属性吗?)得到了完全相同的错误。
根据ASP.NET Core Blazor forms and validation页面,您应该将InputText元素的声明更改为<InputText @bind-Value="@Model.Name" placeholder="Name"/>
我添加@字符,我的控件就会呈现出来。
发布于 2020-07-13 17:56:43
添加到InputText
字段无意义的咒语
ValueExpression="@( () => Model.Name )"
是的,这是没有意义的,但这是有效的。
不幸的是,Blazor
并不是一个真正的商业开发环境,因为Blazor
不支持VB.NET
,不支持jQuery
,不支持Visual Studio Designer,不方便ASP.NET
开发组件,如Pager
,DataGrid
等等。这只是一个有很多问题的清晰的裸体想法。
https://stackoverflow.com/questions/57027047
复制相似问题