Compile error when invoking custom method on numeric input change event

I'm trying to implement something where when a numeric field changes, it automatically enters a value in another property. I've been having problems doing this as I learn more about Radzen so have stripped it back to a minimum to try and find the problem and cannot overcome this issue.

I have a simple entity and have created a test project. On either an Add or Edit page, I add a change event to a numeric input field.

It invokes a custom method which then triggers a notify with the summary set to ${result} which looks like this:

int GetPoints()
{
     return 15;
}

When I come to compile the application in wither Radzen or Visual Studio, I get this compilation error:

Argument 2: cannot convert from 'method group' to 'EventCallback' RadzenTest C:\Test\server\Pages\AddPokerResult.razor

If I look at the output generated in the razor file, I can see the offending line:

<RadzenNumeric style="display: block; width: 100%" @bind-Value="@((pokerresult.Position))" Name="Position" Change="@PositionChange">
</RadzenNumeric>

That Change="@PositionChange" event points to this method in the razor.designer.cs file:

protected async System.Threading.Tasks.Task PositionChange(decimal? args)
{
     var getPointsResult = GetPoints();
}

I can't make my mind up if I'm doing something wrong or if this is potentially a bug.

Any help would be appreciated.

Thanks.

Update

I found this issue on GitHub: https://github.com/dotnet/aspnetcore/issues/12226

If you read down to https://github.com/dotnet/aspnetcore/issues/12226#issuecomment-518860109 pranavkm suggests this solution:

  1. Use a delegate or perform an explicit cast
<InputSelect ValueChanged="(int x) => ChangedInt(x)" />

<InputSelect ValueChanged="(Action<int>)ChangedInt" />

So I manually changed:

<RadzenNumeric style="display: block; width: 100%" @bind-Value="@((pokerresult.Position))" Name="Position" Change="@PositionChange">
</RadzenNumeric>

to read:

<RadzenNumeric style="display: block; width: 100%" @bind-Value="@((pokerresult.Position))" Name="Position" Change="(int x) => PositionChange(x)">
</RadzenNumeric>

and the application now compiles and the expected notification popup occurs with the value of 15 in it as expected.

Hi @Paul_Pitchford,

Try adding an attribute called TValue with value int:

image

We will try to address the issue in Radzen so setting TValue isn't required.

That didn't work I'm afraid. I presume you meant adding the attribute to the numeric input box?

It produces this:

<RadzenNumeric style="display: block; width: 100%" @bind-Value="@((pokerresult.Position))" Name="Position" Change="@PositionChange" TValue="int">
</RadzenNumeric>

But it doesn't compile. We do however get a different error message:

No overload for 'AddPokerResultComponent.PositionChange(decimal?)' matches delegate 'Func<int, Task>'

What is the type of the Position property? I thought it was an int but it seems this is not the case.

You're correct, it's an integer.

Then the signature of the PositionChange event is wrong - it should have had int as an argument. Are you using the latest Radzen version?

I must have been a version behind because doing an update and using the fix you suggested has worked.

Thank you.

I did the Radzen update today (after putting it off a few days) and this problem has reared it's head again. If I don't use the TValue attribute I get this error:

dotnet: Pages\EditFinish.razor(57,128): error CS1503: Argument 2: cannot convert from 'method group' to 'EventCallback' [C:\Code\SuttonPokerResults\server\SuttonPokerResults.csproj]
obj\Debug\netcoreapp3.1\Razor\Pages\EditFinish.razor.g.cs(155,174): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type [C:\Code\SuttonPokerResults\server\SuttonPokerResults.csproj]

If I use the TValue attribute (as per the previous fix) I now get:

dotnet: Pages\EditFinish.razor(57,128): error CS0123: No overload for 'EditFinishComponent.PositionChange(decimal?)' matches delegate 'Func<int, Task>' [C:\Code\SuttonPokerResults\server\SuttonPokerResults.csproj]
obj\Debug\netcoreapp3.1\Razor\Pages\EditFinish.razor.g.cs(155,174): error CS1662: Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type [C:\Code\SuttonPokerResults\server\SuttonPokerResults.csproj]

Position is definitely an int, I don't know why it's referring to a decimal? Any pointers?

Thanks,

Paul.

@Paul_Pitchford we will have to reproduce this at our end. Send us the application to info@radzen.com. Delete the server\bin and server\obj directories to keep the file size small.

BTW did you update this page in any way before or after the update? You can check in source control if there are any differences in the JSON file (should be edit-finish.json).

I've sent it across. Thank you.

Yes the file has changed but I was going to address that in another thread but I'll quickly mention it here. When I had the templating issue on the dropdowns for displaying multiple columns you gave me this code:

${((data as Player).Forename)} ${((data as Player).Surname)}

This no longer works. So, I had modified the template to at least make it work and then I was going to come back to you on that issue.

Thanks.

I think we managed to reproduce the compilation error.

The workaround indeed doesn't work (and shouldn't have been required). We will try to fix that as well.

Getting this compile error today as well. Weird, the change event worked a day or so ago.

Any workarounds?

Today's release contains a fix for this issue. You need to add the Change handler again though.

Thanks! Works great!

I'm getting the same error with a change event of an inline edit grid textbox.

dotnet: obj\Debug\netcoreapp3.1\Razor\Pages\Shipment.razor.g.cs(771,280): error CS1503: Argument 2: cannot convert from 'Microsoft.AspNetCore.Components.EventCallback<int?>' to 'Microsoft.AspNetCore.Components.EventCallback'

TValue on the textbox is 'dynamic'.

                    <RadzenGridColumn TItem="MailBlazorC.Models.Inventory.ShipmentItemsDetail" Context="mailBlazorCModelsInventoryShipmentItemsDetail" Property="GrossWt" Title="Gross Wt">
                  <EditTemplate Context="mailBlazorCModelsInventoryShipmentItemsDetail">
                    <RadzenNumeric style="display: block; width: 100%" @bind-Value="@(((mailBlazorCModelsInventoryShipmentItemsDetail.GrossWt)))" TValue="dynamic" Name="GrossWt" Change="@((args) =>GrossWtChange(args, mailBlazorCModelsInventoryShipmentItemsDetail))">
                    </RadzenNumeric>
                  </EditTemplate>
                </RadzenGridColumn>

I tried changing to 'int' but had no effect. Perhaps relating to the fact that the error is in generator (...g.cs) file?

To clarify, the text box is an Edit Template of a nested grid - so a few Edit Templates deep - if that matters(?)