InvalidOperationException: Microsoft.AspNetCore.Components.Forms.InputText requires a value for the 'ValueExpression' parameter. Normally this is provided automatically when using 'bind-Value'.
means an InputText was given Value on its own. Replace
Value="@person.Name" with @bind-Value="person.Name" and the
page renders.
The project builds with 0 Error(s) and one warning, BL0008, about the
[SupplyParameterFromForm] property's initializer, which is unrelated to this
error; the exception comes when the page is
requested, and the browser gets a 500. Switching the attribute to
@bind-Value is the whole fix.
The error
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.InvalidOperationException: Microsoft.AspNetCore.Components.Forms.InputText requires a value for the 'ValueExpression' parameter. Normally this is provided automatically when using 'bind-Value'.
at Microsoft.AspNetCore.Components.Forms.InputBase`1.SetParametersAsync(ParameterView parameters)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.SupplyCombinedParameters(ParameterView directAndCascadingParameters)
...
That is from the app's console log; curl.exe -s -i on the page answered
HTTP/1.1 500 Internal Server Error. The top frame is
InputBase`1.SetParametersAsync, the base class of InputText. No frame
in the trace names the page itself, so search your pages for InputText tags
that have Value but no @bind-Value.
Why it happens
The message names its own condition: InputText requires a
ValueExpression parameter, and bind-Value is what normally
supplies it. Writing @bind-Value="person.Name" passes the value, a change
callback and an expression that points at person.Name. Writing only
Value passes the value and nothing else, so the component has no expression
and throws while its parameters are set, which is before the form renders any HTML.
The page that failed:
<EditForm Model="person" FormName="profile">
<InputText Value="@person.Name" />
<button type="submit">Save</button>
</EditForm>
The fix
<EditForm Model="person" FormName="profile">
<InputText @bind-Value="person.Name" />
<button type="submit">Save</button>
</EditForm>
After the change the build again reported 1 Warning(s) (the same BL0008) and
0 Error(s), the page answered
HTTP/1.1 200 OK, and the rendered form held
<input name="person.Name" class="valid" value="David Chen" />, the value
from the model.
If you deliberately want Value with your own change handler, the message
tells you what is missing: pass a ValueExpression as well, pointing at the
same property. That variant was not run for this post; @bind-Value is the
one that was tested.
How it was reproduced
A fresh project from dotnet new blazor -o Af --interactivity None on .NET SDK
10.0.403 with the ASP.NET Core 10.0.14 runtime, one static server-rendered page with the
EditForm above and a [SupplyParameterFromForm] model holding the
fictional name David Chen. The app ran with
dotnet run --no-build --urls http://127.0.0.1:15751, the page was fetched with
curl.exe -s -i http://127.0.0.1:15751/profile, and the exception was read from
the redirected console log.
Frequently asked
- What does ValueExpression mean in Blazor InputText?
- It is the parameter that tells the input component which model property it edits. bind-Value supplies it together with Value and ValueChanged; Value alone does not.
- Why does my Blazor page build but return 500 with InputText?
- The missing ValueExpression is only checked when the component receives its parameters at render time, so dotnet build reported 0 errors and the request failed with InvalidOperationException.
- How do I fix InputText requires a value for the ValueExpression parameter?
- Change Value="@person.Name" to @bind-Value="person.Name". In the test on .NET 10 the page then returned 200 and showed the model value in the input.
More decoded errors in the Fixes category. Forms that fail one step earlier are covered in EditForm requires a Model parameter, or an EditContext parameter.