0

How can I send two parameters in one request?
I know how to send one request with one parameter.

I use postman to send the requests.
This is the person code:

public class Person { public string Name { get; set; } public string Position { get; set; } } 

And this is my controller code:

[HttpPost("Add")] public async Task<IActionResult> Add(List<IFormFile> files, Person person) 

How can I realize this?

2 Answers 2

1

Create a class that holds both parameters.

public class AddRequest { public Person Person {get; set;} public List<IFormFile> Files {get; set;} } 

then change your controller to accept the wrapper class

 [HttpPost("Add")] public async Task<IActionResult> Add(AddRequest request) 

then just create an instance of the AddRequest class, populate it with your parameters, and POST it to the 'Add' endpoint

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

2 Comments

Thank you very much
how i can post from client side ? i dont have idea
0

If you are sending multipart/form-data from front-end then you can receive it like as

[HttpPost("Add")] public async Task<IActionResult> Add(Person person) { var files = Request.Form.Files; //your code here } 

I hope it will fill your requirement

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.