0

I have a MicroServices project in which a Controller is not working as expected all the time.

I supply some JSON in the HTTP request which looks like this:

\"Active\": true,

and instruct the method to create a DataTable thus:

[HttpPost("Add")]
public async Task<IActionResult> Add([Required, FromBody] DataTable tableData) (...)

The problem I'm facing is that sometimes the DataTable.Row column type is boolean, and other times it is a string containing "True" (note the casing), but that behaviour isn't consistent.

Does anyone know why?

radders
  • 923
  • 8
  • 29
  • Can you show the actual content you post? I ask because what you've shown is a JSON fragment, and invalid as such, given that it shows the backslash. Properties needs to be inside an object. – Lasse V. Karlsen Nov 02 '20 at 14:28
  • 3
    I really wouldn't recommend using `DataTable` for your MVC models. – DavidG Nov 02 '20 at 14:29
  • I've been using DataTables for several years in this way without problems. Yes, it is only a fragment - what I'm showing is that a BOOL is being passed, not a string. What I want to know is why a string column type is being created... – radders Nov 02 '20 at 14:38
  • I think I've found what's breaking it.... In the first row in the data, Active is null. In the second row it is true. So it seems that the null is creating a string column type, rather than a bool? – radders Nov 02 '20 at 14:50
  • Maybe _some_ objects in your json have active as string? And then json serializer infers string as column type. – Evk Nov 02 '20 at 14:51

0 Answers0