-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Cant use asp-for tag helpers with nullable model #40327
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
Comments
@G1Vh is there compile or runtime error, |
Compile |
This error makes sense - |
As temporal workaround it works, yes. But it still be wrong behavior, compiler should allow writing |
Thanks for contacting us. We're moving this issue to the |
cc @mkArtakMSFT @pranavkm for consideration for .NET 7 |
Is there an existing issue for this?
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
andInputTagHelper.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
Exceptions (if any)
Dereference of a possibly null reference
.NET Version
6.0.200
Anything else?
No response
The text was updated successfully, but these errors were encountered: