model
public class modelVenta {
public int idvendedor { get; set; }
public int idcliente { get; set; }
public int idproducto { get; set; }
public int cantidad { get; set; }
public decimal precio { get; set; }
public DateTime fecha { get; set; }
}
public class modelVentas {
public List<string> modeloVenta { get; set; }
}
Controller
[HttpPut]
[Route("api/ventas/Add")]
public HttpResponseMessage putVentas( List<modelVentas> data)
{
return new HttpResponseMessage { StatusCode = HttpStatusCode.OK };
}
JSON
var data = [{
"idvendedor": 1,
"idcliente": 1,
"idproducto": 1,
"cantidad": 2,
"precio": 12.0,
"fecha": 1476445327124
}, {
"idvendedor": 1,
"idcliente": 1,
"idproducto": 2,
"cantidad": 4,
"precio": 23.0,
"fecha": 1476445327124
}, {
"idvendedor": 1,
"idcliente": 1,
"idproducto": 1,
"cantidad": 4,
"precio": 35.0,
"fecha": 1476445327124
}];
Send data
$http.put("http://localhost:54233/api/ventas/Add", JSON.stringify({
modeloVenta: data
})).then(function () {
toastr.info('Elemento insertado correctamente');
});
I validate the Json in http://jsonlint.com/ and is ok, but every time I send from AngularJS, api controller web, always receives Null.
please community, someone could help me solve this problem?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…