kolek
kolek

Reputation: 699

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?

Upvotes: 47

Views: 30661

Answers (5)

Eleh Gilbert
Eleh Gilbert

Reputation: 1

This error typically occurs when the ValueExpression parameter is not provided, which is usually handled automatically when using @bind-Value.

I faced same issue using @bind-Value. Try changing the ValueEpression instead of @bind-Value

A simple example is:

<InputText @bind-Value="clientRecord.clientName" ValueExpression="() => clientRecord.clientName" />

Upvotes: 0

Viacheslav
Viacheslav

Reputation: 1322

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.

Upvotes: 3

Eric Bourque
Eric Bourque

Reputation: 174

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

Upvotes: 9

DharmaTurtle
DharmaTurtle

Reputation: 8377

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

The v is uppercase. Use @bind-Value

Upvotes: 155

Jacques
Jacques

Reputation: 143

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.

Upvotes: 14

Related Questions