1
I own the Object var obj = { nome: "Felipe", idade: 23 }
I created an ajax call by jquery like this:
$.ajax({
url: 'ConfigCode/UpdateOptionsStatus', // route controller na web
type: 'PUT',
data: JSON.stringify(obj),
contentType: "application/json; charset=utf-8",
dataType: "json"
});
In the Web Controller ConfigCode
I created the method UpdateOptionsStatus
:
[HttpPut]
public ActionResult UpdateOptionsStatus(object objectToSend)
{
RestHelper.Put(objectToSend, $"ConfigCode/Update");
return new EmptyResult();
}
What in the objectToSend
in fact carries a {object}
On the controller ConfigCode
API, I created the method Update
to receive it:
[HttpPut, IgnorePermission]
public HttpResponseMessage Update(object optionsToUpdate)
{
(...)
if (result == null)
return NotFound();
return Ok(result);
}
But the {Object}
sent. An empty tag arrives {{}}
in optionsToUpdate
why instead of receiving a
object
, does not create a model class and takes it as parameter? are only 2 very simple properties– Ricardo Pontual
yes it worked. I did an Update(List<Viewmodelcriada> optionsToUpdate) and changed the object to an object array with the Viewmodel properties.
– Luke Negreiros
good Luke, serializer/deserializer works best with defined types, Object, Dynamic and the like are complicated for this :)
– Ricardo Pontual