I am trying to pass list of class object in my ASP.Net Core 2.1 Controller. I am getting empty object with count 0. I have used attribute [FromQuery], [FromRoute]
but the result remain same. My parameter class is as follows:
public class Employee
{
public int EmployeeCode { get; set; }
public int EpfNumber{ get; set; }
}
I am trying to get the list of Employee Class in my Controller like this:
[Route("[action]")]
public async Task<ActionResult<int>> GetEmployeeByEmpCode([FromQuery]List<Employee> emp)
{
//----------Doing my stuff.
return Ok(1);
}
Here in the emp
parameter I am getting empty list. By googling the issue, I got that I need to use [FromUri]
. But the [FromUri]
is used in Asp.Net WebApi 2, not asp.net core. If I simply add list of string as parameter then it works. The problem is with the class object as peremeter.
My question is how to pass list of class object as peremeter in Asp.Net Core 2.1 controller?