asp.net core create image doesnt handle nulls

Anonymous
2023-07-14T11:46:28.9166667+00:00

This scenario doesn't work, when I try to create a record without image.

https://github.com/KalyanAllam/DoctorClinic

Capturenew.JPG

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,017 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Zhi Lv - MSFT 29,791 Reputation points Microsoft Vendor
    2023-07-17T03:08:38.7266667+00:00

    Hi @KALYANA ALLAM

    asp.net core create image doesnt handle nulls. This scenario doesn't work, when I try to create a record without image.

    Try to use F12 developer tools to debug your code, you can find that when create a record without image, the ModelState is invalid, so the insert command will not execute.

    User's image

    To solve this issue, try to change the parameter as nullable (IFormFile? image).

            [HttpPost]
            [ValidateAntiForgeryToken]
            public async Task<IActionResult> Create([Bind("Visitid,Notes,Visitdate,Patientid,Clinicianid")] Visit visit, IFormFile? image)
            {
    

    Then, the result as below:

    User's image


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Dillion

    0 comments No comments