I want to be able to render a form with Blazor (Server Side Rendering) but I am not getting the right syntax.
<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");
}
}
and
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; }
}
But I get this error
Microsoft.AspNetCore.Components.Forms.InputText requires a value for the 'ValueExpression' parameter. Normally this is provided automatically when using 'bind-Value'.
How does one render the page and do a simple post to the server?
For me, it was because I was using @bind-value.
The v is uppercase. Use @bind-Value
I've been struggling with the exact same thing tonight. I omitted the "@" sign before the "bind-Value" (can I call it a property?) and got the exact same error.
According to the ASP.NET Core Blazor forms and validation page you should change your InputText element's declaration to <InputText @bind-Value="@Model.Name" placeholder="Name"/>
I add the @ character and my control renders.
I forgot the @ infront of @bind-Value="@Model.Name". It should be @bind-Value="@Model.Name", not bind-Value="@Model.Name".
Add to InputText field meaningless spell
ValueExpression="@( () => Model.Name )"
Yes, this is no sense, but this is working.
Unfortunately, Blazor is not a really environment for commercial development, because Blazor not support VB.NET, not support jQuery, not supported by Visual Studio Designer, has no convenient for ASP.NET developer components like Pager, DataGrid and so on. Its only a clear naked idea with a lot of issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With