I have created a method of get type with class type parameter in web api (.NET MVC).Like below code
class Employee
{
int Ind;
int Empno;
}
[HttpGet]
public DataTable GetEmployee(Employee e)
{
.............
.............
return new DataTable();
}
Below code I am using to call API:
internal DataTable CallApi()
{
var client = new RestClient("......./Ctrl/GetEmployee");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Content-Type", "application/json");
Employee emp = new Employee()
{
Ind = 1,
Empno = 10001
};
var body = JsonConvert.SerializeObject(emp);
request.AddParameter("application/json", body, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
DataTable dt = new DataTable();
dt = JsonConvert.DeserializeObject<DataTable>(response.Content);
return dt;
}
I want to call above API method from ASP.NET project, Abobe code is hitting to api method, But problem is that Parameter that I am sending to call api method is not getting in api method parameter,
In objcet Employee e , Parameter is not getting the sent objct.