I am creating a webAPI using the webAPI2.
I have created some domain model classes which are part of the models folder inside the webAPI project.
This is the DataRequest Model class
public class DataRequest
{
Field1
Field2...
}
The Controller class and Action method are below.
[RoutePrefix("api/Data")]
public class DataController : ApiController
{
[Route("")]
[HttpPost]
public IHttpActionResult Post(DataRequest request)
{
}
}
And the data request body issued in postman in json
{
Field1:"Some Value",
Field2: "Some Value"
}
The model binding works perfectly and I get values in the POST action method for field1 and field2.
I have a separate project with helper methods and I want to extend this project by adding some business logic with the Data Request class. Hence I have created a separate project with models and added that project as reference to helpers and api projects.
The project compiles successfully with this setup. But when I issue a request in Postman, the Action method gets called but I get null for all the fields in the request parameter.
Googling pointed me to some links which explain loading controller classes from separate assembly but there is no reference to load models from separate assembly.
Is this allowed and if yes, can anyone let me know how to get this working.