Open
Description
Hi, i have a problem in angular when send data in post method, in my client
this.prueba = function (id, nombre) {
return $http.post(ApiURL + "AEmpleado/prueba", { id: id, nombre: nombre })
.then(
function (respuesta) {
MensajeServices.MostarMensaje("", "Se elimino el Registro Correctamente", "success", null);
//vm.CargarTabla();
return respuesta
},
function (respuesta) {
console.log(respuesta.data.Message);
return false;
}
);
}
in my server
[RoutePrefix("api/AEmpleado")]
[MvcStyleBinding]
public class AEmpleadoController : ApiController
{
[HttpPost, Route("prueba")]
public IHttpActionResult prueba(int id, string nombre)
{
return Ok();
}
}
The error is:
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Net.Http.Formatting.FormDataCollection' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'id', line 1, position 6.
in
private class MvcActionBinding : HttpActionBinding
{
// Read the body upfront , add as a ValueProvider
public override Task ExecuteBindingAsync(HttpActionContext actionContext, CancellationToken cancellationToken)
{
HttpRequestMessage request = actionContext.ControllerContext.Request;
HttpContent content = request.Content;
if (content != null)
{
FormDataCollection fd = content.ReadAsAsync<FormDataCollection>().Result;
if (fd != null)
{
IValueProvider vp = new NameValuePairsValueProvider(fd, CultureInfo.InvariantCulture);
request.Properties.Add(Key, vp);
}
}
return base.ExecuteBindingAsync(actionContext, cancellationToken);
}
}
anybody help?
Sorry for my english
Metadata
Metadata
Assignees
Labels
No labels