2

when calling a c# method from js ajax I am getting 404 error on console

I tried following ways to send data to c# method

data: '{ name: "test" }'
data: JSON.stringify({ 'name': 1234 }),

$.ajax({
    url: "/api/system/AddCertificateFromStore",       
    type: 'POST',
    data: '{ name: "divya" }',
    complete: function (xhr, status) {
    },
    error: function (xhr, status, err) {
    }
    },
    cache: false,
    contentType: "application/json; charset=utf-8",
    processData: false,
    dataType: 'json'

C# method is something like this

[HttpPost]
public HttpResponseMessage AddCertificateFromStore(string CertificateName)
{
    // Make the web request
    HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

    return response;
}

Would like to send the parameters to C# method correctly so that it is being called from js ajax

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49

1 Answers1

1

You should add a FromBody decorador in your C# Action

[HttpPost] public HttpResponseMessage AddCertificateFromStore([FromBody] string CertificateName) {

Rander Gabriel
  • 637
  • 4
  • 14