is that I have a PUT and I want to capture the value of the field that I am going to update, but in the database in a SQL_Variant
so to do so I have to send an object when sending it to the database, this is my PUT
[HttpPut("{empid}/{codigo}/{valor}")]
public async Task<IActionResult> Put(int empid, string codigo, [FromRoute]object valor)
{
try
{
return Ok(await repository.UpdateAsync(empid, codigo, valor));
}
catch (Exception e)
{
return BadRequest(e.ToString());
}
}
If I [FromRoute]object valor
change it to string or int here, it receives it correctly, but if I leave it in type Object
it will get Null and it doesn't work for me, how do I capture an object from the Controller route?
Define it as a string and it will receive all the types you send, then inside the controller code you can cast to really see what type it is
As you will see, you should see what type it is to assign the string that arrives or the value that is converted to a numeric if it is a number
It could be seen if it is resolved with a custom ModelBinding , but I find it difficult if you send the value in the url, perhaps if you did it as part of
body
the put