Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Binding nullable int to input causes null reference exception #466
Minimal repro steps
Consider this Blazor page:
Page should render without exceptions
A nullref exception is thrown:
Further technical details
Making the nullable int non-nullable wil fix this.
Currently i'm trying to make working selectable list or it call maybe drop-down list (I'm back-end developer). Anyway, can't make it working with drop-down list if drop-down list items is dynamic get data from server.
This is enum drop-down list working great:
This one is struggling:
Also possible that i'm just doing it wrong (I guess it 90% possibility)
This issue appears for any non string binding that is null, the code that causing this is
The exception occurs because calling
For string, null works as there's a different overload.
The interesting part is that
but JS assumes it to be always
This odd design appears to be for
I feel like this is a hole. If someone uses entity framework to bind to a database, it will force them to create new entities taking care of nulls. Would love to see some configuration that allows treating nulls as "" for strings and nulls as 0 for ints. I don't want to get into a philosophical discussion on why they aren't equal. In my mind I realize that but the application has to deal with it somehow, and I would prefer to handle it globally not field by field.
If I have a nullable string in a database and I want to bind using blazor I don't like having to do some type of extension method to solve this over and over.