This has been driving me mad for ages. I took the following piece of working code
<input @onchange="@((ui) => Console.WriteLine(ui.Value))" />
and copied it to a new blazor component project. I then started getting the error
error CS1660: Cannot convert lambda expression to type 'bool' because it is not a delegate type
As this lost me quite a lot of time and the error is very misleading I thought I'd write it up.
The issue is a missing @using
add the following in and it all works.
@using Microsoft.AspNetCore.Components.Web
I'm guessing there is some extension method in that namespace that makes the magic work in the razor generated code...
Adding the @using
statement unfortunately didn't work for me. Apparently, you have to define the lambda expression directly inside the quotes now, without wrapping it inside @(...)
, like this:
<input @onchange="changeEventArgs => Console.WriteLine(changeEventArgs.Value)" />
See this reference for examples: https://learn.microsoft.com/en-us/dotnet/architecture/blazor-for-web-forms-developers/components#event-handlers
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