1
I am with the problem that is the following, I am consuming a service where it receives a parameter as input, in the frontend I send this parameter via ajax, 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?