0

I am trying to build an ASP.NET MVC web service in which I am trying to make a POST call in javascript using jQuery ajax as below.

$.ajax({
      url: "/bug/CreateBug",
      type: "POST",
      data: rowData,
      contentType: "application/json",
      datatype: "json", //return type
      success: function (data) {
          console.log(data);
      },
      error: function (xhr) {
          alert('error');
      }
  });

I keep getting the error TypeError: e is undefined. I tried adding a log statement just before this ajax call and things are working fine. Not sure what am I missing out on. My rowData looks something like below.

{
    "Date": "2016-12-31",
    "Id": "1234-csj4-sadf-random",
    "Scenario": "abc",
    "IsFixed": "No"
}

My C# code in the controller looks something like this

[HttpPost]
public JsonResult CreateBug(string jsonRequest)
{
    var bugId = GetBugId(jsonRequest);

    return this.Json(bugId, JsonRequestBehavior.AllowGet);
}

I tried to test the above POST call using Postman and I got jsonRequest as null. Could someone pls help me out here on how can I get the POST request to work?

Thanks in advance!

3
  • try data:Json.stringify(rowData) Commented Jan 14, 2017 at 11:33
  • can you try JSON.stringify(rowdata) Commented Jan 14, 2017 at 11:34
  • posted updated code plz let me know if it works Commented Jan 14, 2017 at 11:36

1 Answer 1

1
  try it hope it works
  $.ajax({
  url: "/bug/CreateBug",
  type: "POST",
  data: JSON.stringify(rowdata),
  contentType: "application/json",
  datatype: "json", //return type
  success: function (data) {
      console.log(data);
  },
  error: function (xhr) {
      alert('error');
  }
  });

------ on controller do something like this or the best approach is to create model with all these property and MVC will bind it for you.

    [HttpPost]
   public JsonResult CreateBug(string Id, string Date, string IsFixed ,   string Scenario)
 {
    var bugId = GetBugId(jsonRequest);

   return this.Json(bugId, JsonRequestBehavior.AllowGet);
}
Sign up to request clarification or add additional context in comments.

2 Comments

Yeah it is now making the call to the MVC controller, but I am still getting jsonRequest as null in the controller.
@SohamC updated answer please take a look if u still have issue let me know .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.