On front-end I am using Angular 14, Back-end is of Asp.net Core v5.
In asp.net core I have disabled the cors by adding
AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()
Now my other forms are working fine.
But, this form where I am using Form Data is creating an issue. Let see the browser
Now it says its a cors issue. However let me remind us all that I have already added the cors policy and all my other form is working fine.
So in addition to this request, I have added one more header and now my http packet looks like this,
I have added the missing header as well but the result is the same. What could have gone wrong?
Is the formdata culprit? or is the file?
on the server side, I have added the cors policy
and this is my ViewModel
Additionaly this is the action method
So I found the problem and it was not related to CORS policy as such.
The problem was "Model Validation"
I have not mentioned the extra file field which was going to the server in the server's View model.
Later on, I added another property of type "IFormFile?" which would successfully receive the file data from my FormData.