I am using asp.net mvc with jquery… I have made a json call to a controller method and it returns json object [Object object] for me. I dont want that instead i want to get the json string… Any suggestion…
$(document).ready(function() {
$.getJSON('Materials/GetMaterials', null, function(data) {
alert(data);
});
});
I gave alert(data.d); and it is undefined
public JsonResult GetMaterials()
{
var materials = consRepository.FindAllMaterials().AsQueryable();
return Json(materials);
}
getJSON will return a json object. If that isn’t what you want you shouldn’t use it. You can use $.ajax instead and set the content type to text/plain and you will receive the data as a string. I can’t, however, see any reason you would want to work with a string instead of a object.
You can optionally use the JSON.stringify method from the json2 library to turn a object into a string.