Environment used: ASP.NET, jQuery
I have the following AJAX call:
var tempVar = JSON.stringify({plotID:currentId});
$.ajax({
type: "POST",
url: "testPage.aspx/getPlotConfig",
data: tempVar,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$('#xDimLbl').text(msg.xDim);
$('#bDimLbl').text(msg.bDim);
}
});
The code behind has the method getPlotConfig(string plotID) defined as
public static string getPlotConfig(string plotID)
{
string x = "T1";
string b = "T2";
return Json(new { xDim= x, bDim= b });
}
Questions:
- When I do a build, I get the error: The name ‘Json’ does not exist in the current context Which namespace is amiss?
- Along with the two strings x and b, I would like to return a hash table whose key is a string and value is a list of comma separated strings. How do I do that and how to access each key value pair at the client side?
cheers
This could be referring to the Json method used in ASP.NET MVC controller. As your
getPlotConfigfunction is static you cannot use this method. You may take a look at PageMethods. Here’s an example:And in javascript: