0
good morning. I’ve been trying for a few days trying to capture a POST made in Javascript by webapi c# and the most I can is the webapi telling me that the expected parameter is NULL.
var objFornecedor = {
ID_FORNECEDOR: 38,
NOME: "cleverton teste",
CNPJ: "546546546546",
ENDERECO: "rua c",
BAIRRO: "novo teste",
CIDADE: "serrinha",
SITUACAO: "1",
DATA_CADASTRO: new Date(2015,02,02)
}
$.ajax({
contentType: 'application/json; charset=utf-8',
data: objFornecedor,
url: 'http://localhost:3190/servicowebapi/fornecedor/incluir',
success: function(retorno)
{
alert('funcionou');..........
and here are the codes you receive
[HttpPost]
[ActionName("incluir")]
public void Post(FORNECEDOR objFornecedor)
{
ctx.FORNECEDOR.Add(objFornecedor);
ctx.SaveChanges();
}
Call me that mistake. An Exception of type 'System.Argumentnullexception' occurred in Entityframework.dll but was not handled in user code
Additional information: Value cannot be null. ctx.FORNECEDOR.Add(objFornecedor); objFornecedor is NULL
and here follows my class SUPPLIER
public partial class FORNECEDOR
{
public int ID_FORNECEDOR { get; set; }
public string NOME { get; set; }
public string CNPJ { get; set; }
public string ENDERECO { get; set; }
public string BAIRRO { get; set; }
public string CIDADE { get; set; }
public string SITUACAO { get; set; }
public Nullable<System.DateTime> DATA_CADASTRO { get; set; }
}
I’ve already done whatever you imagine, just tested for a page ASP.Net with the same code to consume and guess ? Asp.net consumes (jQuery), but inside the Cordova plugin I can only read.
– Cleverton
I’ve already added all the verbs in Webconfig POST, GET, PUT, DELETE, OPTIONS
– Cleverton
<add name="Access-Control-Allow-Origin" value="*" />
– Cleverton
@Cleverton, it would be nice to put in the question that is using Cordova. I did using an ASP.Net page and gave in the same as you. If I find time, I try to do with Cordova.
– Filipe Oliveira