© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
17 replies
Utsuhoagie

✅ Nullable DateTimeOffset field in a [FromForm] model is always null

I have a React Native (Expo running on Expo Go on an Android specifically) client and an ASP.NET Core Web API server.
My client sends requests with content type
multipart/form-data
multipart/form-data
, and supplies the correct values for each field. Specifically in this example, the
BirthDate
BirthDate
field is either omitted entirely from the
FormData
FormData
, or it's given an ISO timestamp string with Z offset. I don't send
null
null
,
undefined
undefined
,
''
''
or anything like that.
But when the request reaches the server, the model's nullable
BirthDate
BirthDate
field is always null with either cases (client doesn't include the field in its
FormData
FormData
, OR the field's value is something like
2023-04-27T02:50:23.636Z
2023-04-27T02:50:23.636Z
). Other fields are still sent properly (either given a proper value, or is
null
null
once the server reads the request).

public class UpdateSelfRequest
{
    public string NationalId { get; set; } = string.Empty;
    public string? Phone { get; set; }
    public string? Address { get; set; }
    public DateTimeOffset? BirthDate { get; set; }
    public IFormFile? Image { get; set; }
}

[HttpPut("UpdateSelf/{NationalId}")]
[Authorize(Roles = AuthRoles.Employee)]
[Consumes("multipart/form-data")]
public async Task<IActionResult> UpdateSelf(
    [FromRoute] string NationalId,
    [FromForm] UpdateSelfRequest req)
{
    // -----> Here, req.BirthDate is null despite the client sending a value
    var result = await _service.UpdateSelf(NationalId, req);
    if (!result.Success)
    {
            return Forbid();
    }

    return Ok();
}
public class UpdateSelfRequest
{
    public string NationalId { get; set; } = string.Empty;
    public string? Phone { get; set; }
    public string? Address { get; set; }
    public DateTimeOffset? BirthDate { get; set; }
    public IFormFile? Image { get; set; }
}

[HttpPut("UpdateSelf/{NationalId}")]
[Authorize(Roles = AuthRoles.Employee)]
[Consumes("multipart/form-data")]
public async Task<IActionResult> UpdateSelf(
    [FromRoute] string NationalId,
    [FromForm] UpdateSelfRequest req)
{
    // -----> Here, req.BirthDate is null despite the client sending a value
    var result = await _service.UpdateSelf(NationalId, req);
    if (!result.Success)
    {
            return Forbid();
    }

    return Ok();
}


Logs in screenshot:
image.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

✅ Model Null
C#CC# / help
3y ago
Non-Nullable field (WPF)
C#CC# / help
2y ago
❔ Non-nullable field 'rating' must contain a non-null value when exiting constructor
C#CC# / help
4y ago
Warning: NULL literal or a possible NULL value is being converted to a non-nullable type.
C#CC# / help
2y ago