0

I'm trying to add company with multiple employees with their picture. But I'm facing an issue while posting request, not worrying about internal logic.

There are 2 tables Company & Employee and I want to add company with multiple employees and their picture in a single post request, but I'm getting like this in Swagger:

enter image description here

Instead I want array of this... want this block multiple times:

enter image description here

Please, tell me how can I implement it to get the result I want?

Controller

[HttpPost]
public async Task<ActionResult<Unit>> CreateCompany([FromForm] CreateCompanyRequestViewModel Company)
{
        // 
}

EmployeeRequestViewModel

public class EmployeeRequestViewModel
{
    public string EmployeeName { get; set; };
    public IFormFile ProfileImage { get; set; };
}

CompanyViewModel

public class CreateCompanyRequestViewModel
{
    public string CompanyName { get; set; };
    public IFormFile CompanyLogo { get; set; };
    public List<EmployeeRequestViewModel> Employees { get; set; };
}
0

1 Answer 1

1

You could try with postman as below:

enter image description here

Result:

enter image description here

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

6 Comments

Want list of Employees [ having EmployeeName & ProfileImage ] dynamically...
What does your dynamically mean?
You could check this document related:learn.microsoft.com/en-us/aspnet/core/mvc/models/…
Array Of Employees Will Come From Front-End.... don't want To Use hard coded implementation like employee[0], employee [1]... Coz we don't know how many employees user will add...
unfortunatly,there seems no other default solutions ,may be you could try custom-model-bindinghttps://learn.microsoft.com/en-us/aspnet/core/mvc/advanced/custom-model-binding?view=aspnetcore-6.0
|

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.