Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
After #37510 we can mark model as nullable like @model MyModel?
, but then using asp-for tag helpers
<input asp-for="Id" type="hidden">
<label asp-for="Name" class="d-flex w-50"></label>
shows "Dereference of a possibly null reference" during view compilation.
When model not marked nullable and real passed model is null - inputs renders correctly:
<input type="hidden" data-val="true" data-val-required="The Id field is required." id="Id" name="Id" value="">
<label class="d-flex w-50" for="Name">TestName</label>
Probably problem is LabelTagHelper.ModelExpression
and InputTagHelper.ModelExpression
is not nullable but can really accept null (#5680 shows that Microsoft.AspNetCore.Mvc.TagHelpers not annotated)
Expected Behavior
View compiled without errors and renders correct inputs
Steps To Reproduce
- Mark page model as nullable
- 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