The parameter dictionary contains a null entry

Asked

Viewed 1,020 times

1

I am with the problem that is the following, I am consuming a service where it receives a parameter as input, in the I send this parameter via , but it returns as error and says that I did not pass the parameter:

Frontend:

 $.ajax({
      type: "POST",
      url: "http://localhost/api/Simplex/PostLinear",
      contentType: "application/json; charset=utf-8",
      data: {"id": '1'},
      dataType: "json",
      success: function (result) {
           alert(result);
      },
     error: function (request, status, errorThrown) {
           alert(request.responseText);
      }
});

Backend:

 public class SimplexController : ApiController
{
    //PostLinear
    public string PostLinear(int id)
    {

and returns that message:

{"Message":"The request is invalid." ,"Messagedetail":"The dictionary parameter contains a null entry for the type id parameter which does not allow the System.Int32 unattainable value for the method Postlinear String(Int32)' in 'TCC.Controllers.Simplexcontroller'. An optional parameter must be a type of reference means a type that allows for a set or declared value as an optional."}

In case I change the url of the request to http://localhost/api/Simplex/PostLinear?id=1 it works, but I want to pass the parameter by the ajax date, how to proceed?

1 answer

0

Pass id value without quotation marks:

data: {"id": 1},

and note down its function:

[HttpPost]
public string PostLinear(int id){

Browser other questions tagged

You are not signed in. Login or sign up in order to post.