0

I am trying to make an AJax call to a controller method the parameter is null no matter what I try. I have followed all the similar SO posts but to no avail. Sorry if the answer is there, I cant find it. The code I have is...

Ajax Call

 var sguid = $(nTr).attr('id'); $.ajax({ url: "/Dashboard/Reporting/GetBlacklistedSoftwareItems", type: 'POST', dataType: 'json', data: JSON.stringify({guid: sguid}), statusCode: { 404: function() { alert("page not found"); } }, success: function (data) { //DO Something }, error: function () { alert("error"); } }); 

Controller Method

public JsonResult GetBlacklistedSoftwareItems(string guid) { List<DeviceSoftware> ldevice = new List<DeviceSoftware>(); Guid i = Guid.Parse(guid); ReportMethods reportingMethods = new ReportMethods(); ldevice = reportingMethods.GetNonCompliantApplicationReport(CompanyId); DeviceSoftware ds = ldevice.Find(x => x.Device.Guid == i); List<DeviceApplication> da = new List<DeviceApplication>(); if (ds != null) { da = ds.DeviceApplications; } return Json(da, JsonRequestBehavior.AllowGet); } 

The method is being hit its just guid is alway null. sguid does hold the data I am trying to pass. Can someone tell me what I am missing?

1
  • In your $.Ajax() call add contentType: "application/json; charset=utf-8" , then it will bre resolved Commented Apr 25, 2013 at 3:45

3 Answers 3

1

Against everything I read I changed

data: JSON.stringify({guid: sguid}),

To

data: {guid: sguid},

Now working.

Sign up to request clarification or add additional context in comments.

Comments

0

Fred,

You need to make GetBlacklistedSoftwareItems a post method....

try this...

[HttpPost] public JsonResult GetBlacklistedSoftwareItems(string guid) {

Comments

0

Small changes needs to be done.

var sguid = $(nTr).attr('id'); $.ajax({ url: "/Dashboard/Reporting/GetBlacklistedSoftwareItems", contentType: "application/json; charset=utf-8" ,//This is very important type: 'POST', dataType: 'json', Data: JSON. stringify ({guild: squid}), statusCode: { 404: function() { alert("page not found"); } }, success: function (data) { //DO Something }, error: function () { alert("error"); } 

});

Add the contentType: "application/json; charset=utf-8" , to the $.Ajax Call. :)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.