Cant use asp-for tag helpers with nullable model
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
After https://github.com/dotnet/aspnetcore/issues/37510 we can mark model as nullable like `@model MyModel?`, but then using asp-for tag helpers
``
``
shows "Dereference of a possibly null reference" during view compilation.
When model not marked nullable and real passed model is null - inputs renders correctly:
``
`TestName`
Probably problem is `LabelTagHelper.ModelExpression` and `InputTagHelper.ModelExpression` is not nullable but can really accept null (https://github.com/dotnet/aspnetcore/issues/5680 shows that Microsoft.AspNetCore.Mvc.TagHelpers not annotated)
### Expected Behavior
View compiled without errors and renders correct inputs
### Steps To Reproduce
1. Mark page model as nullable
2. Create input or label asp-for for any model field
### Exceptions (if any)
Dereference of a possibly null reference
### .NET Version
6.0.200
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.