Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InputText requires a value for the 'ValueExpression' parameter

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?

like image 886
kolek Avatar asked Jul 14 '19 11:07

kolek


4 Answers

For me, it was because I was using @bind-value.

The v is uppercase. Use @bind-Value

like image 180
DharmaTurtle Avatar answered Nov 17 '22 11:11

DharmaTurtle


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.

like image 21
Jacques Avatar answered Nov 17 '22 12:11

Jacques


I forgot the @ infront of @bind-Value="@Model.Name". It should be @bind-Value="@Model.Name", not bind-Value="@Model.Name".

like image 6
Eric Bourque Avatar answered Nov 17 '22 13:11

Eric Bourque


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.

like image 3
Viacheslav Avatar answered Nov 17 '22 11:11

Viacheslav