Search code examples
asp.netiisasp.net-web-apirethinkdb

ASP.NET Web API IIS hosting REST Methods produces NULL in RethinkDB


I'm making a Web API for handle my Android app's HTTP requests and rethinkDB connection. But something wrong in IIS i think. It produces null values for my User identity when i send POST request to the API. My db is running on localhost.

My POST method is (there is no DB syntax errors.) =

public IHttpActionResult PostNewUserModel(StudentViewModel studentViewModel)
        {
            if (!ModelState.IsValid)
                return BadRequest("Invalid data.");

            var conn = connection();

            var newStudentViewModel = new StudentViewModel
            {
                Id = studentViewModel.Id,
                FirstName  = studentViewModel.FirstName,
                LastName = studentViewModel.LastName
            };

            R.Db(MYDBNAME).Table(MYTABLENAME).Insert(newStudentViewModel).Run(conn);


            return Ok();
        }

I POST'ed this entity =

{
    "Id": 6,
    "FirstName": "Nihat Can Doğamaz",
    "LastName": "CANITIN"
}

But i see this entity in RethinkDB table like this =

{
"FirstName": null ,
"Id": 0 ,
"LastName": null
}

How to solve it ?


Solution

  • I solve the error. DB cannot recognize returned JSON format. It must be identified in POSTMAN. You must select JSON(application/json) Body format to write your JSON objects into your db.