Skip to content

[Blazor] InputNumber does not support the type 'System.Int64' #13215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tnc1997 opened this issue Aug 17, 2019 · 4 comments
Closed

[Blazor] InputNumber does not support the type 'System.Int64' #13215

tnc1997 opened this issue Aug 17, 2019 · 4 comments
Assignees
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed

Comments

@tnc1997
Copy link

tnc1997 commented Aug 17, 2019

If you believe you have an issue that affects the security of the platform please do NOT create an issue and instead email your issue details to secure@microsoft.com. Your report may be eligible for our bug bounty but ONLY if it is reported through email.

Describe the bug

Firstly, a big thank you for all of the work that everyone has put into the Blazor framework.

The InputNumber component does not support binding to properties of the long data type.

To Reproduce

<EditForm Model="@Model">
    <DataAnnotationsValidator/>
    <ValidationSummary/>

    <div class="form-group">
        <label for="name">Name</label>
        <InputText class="form-control" id="name" @bind-Value="@Model.Name"/>
        <ValidationMessage For="@(() => Model.Name)"/>
    </div>

    <div class="form-group">
        <label for="code">Code</label>
        <InputNumber class="form-control" id="code" @bind-Value="@Model.Code"/>
        <ValidationMessage For="@(() => Model.Code)"/>
    </div>

    <button class="btn btn-primary mdi mdi-content-save" type="submit">Save</button>
</EditForm>

@code
{

    private Product Model { get; set; } = new Product();

    public class Product
    {
        [Required] public string Name { get; set; }

        [Required] public long Code { get; set; }
    }

}

System.InvalidOperationException: The type 'System.Int64' is not a supported numeric type.

Expected behavior

Based on this comment, the InputNumber component should support binding to the long type.

Looking through the code, the issue appears to be caused by the checks in this if statement.

If this is the case, then I am happy to create a fork to add targetType == typeof(long).

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.
Include the output of dotnet --info

.NET Core SDK (reflecting any global.json):
 Version:   3.0.100-preview8-013656
 Commit:    8bf06ffc8d

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18956
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100-preview8-013656\

Host (useful for support):
  Version: 3.0.0-preview8-28405-07
  Commit:  d01b2fb7bc

.NET Core SDKs installed:
  3.0.100-preview8-013656 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.App 3.0.0-preview8.19405.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.0.0-preview8-28405-07 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0-preview8-28405-07 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
@pranavkm pranavkm added area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. labels Aug 17, 2019
@pranavkm pranavkm added this to the 3.1.0-preview1 milestone Aug 20, 2019
@pranavkm
Copy link
Contributor

@tnc1997 thanks for the issue report. We'll track fixing this for the next Blazor release.

@gorrilla10101
Copy link

gorrilla10101 commented Aug 22, 2019

I ran into this issue as well and checked the source code. Seems that it was simply missed in the type checking.

if (targetType == typeof(int) ||
                targetType == typeof(float) ||
                targetType == typeof(double) ||
                targetType == typeof(decimal))
            {
                _stepAttributeValue = "any";
            }

because the converter exists in the case statement.

case long @long:
                    return BindConverter.FormatValue(@long, CultureInfo.InvariantCulture);

Also I have noticed that several of the input components have some kind of issue with bindings different types. Would it not be better/easier to consolidate the value conversion into the base class and let it handle it for all the inputs?

@AlbertoPa
Copy link

Any reason why this isn't making it into 3.0?

@ryanbrandenburg
Copy link
Contributor

I almost forgot, thanks @tnc1997! Your investigation made things a lot easier here.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed
Projects
None yet
Development

No branches or pull requests

6 participants