-1

I don't want to read key line by line. Have any good idea?

Code : https://pastebin.ubuntu.com/p/cDTkc6GScY/

1
  • 2
    Might you please edit your question to include your code in the question itself? From How to Ask: If it is possible to create a live example of the problem that you can link to (for example, on sqlfiddle.com or jsbin.com) then do so - but also copy the code into the question itself. Not everyone can access external sites, and the links may break over time. Commented Feb 16, 2021 at 19:03

1 Answer 1

0

What is the best way pass file from angular 11 form to asp.net core 5 web api

To achieving the requirement of posting file from angular frontend to asp.net core web api backend, you can try to create and populate a FormData object with selected file(s), then then inject the HttpClient service and use it to make request(s).

In your asp.net core web api backend, you may need to apply [FromForm] attribute to your action parameter, which would help specify that a parameter or property should be bound using posted form fields.

And you may need to configure and enable CORS in your backend to set the allowed origins and HTTP methods etc. For more information, please check the following doc:

https://learn.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-5.0

Besides, you can refer to the following SO threads to achieve the requirement.

How can update a model with images attach?

How to Upload File from Angular to ASP.NET Core Web API

Sign up to request clarification or add additional context in comments.

2 Comments

If i use ([FromForm] MyModelClass model) its receive everything null inside model
If i use ([FromForm] MyModelClass model) its receive everything null inside model Hi @ShohanurRahman, please share the code of MyModelClass and the actual data you post from client, so that we can help troubleshoot the issue better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.