I have simple JavaScript code in which I want to get an object from a controller and parse it in the script, but in the script, I don't have access to any property of the object.
My object (in the controller):
public class userData
{
public string firstName { get; set; }
public string lastName { get; set; }
public string state { get; set; }
public bool success { get; set; }
}
Script:
function load()
{
var sender = {
userNo : $("#userNo").val(),
}
$.ajax({
type : "POST",
url : "testGetUser",
data : sender,
success:function(data)
{
if(1)
{
$("#section #result0").html(data.firstName);
$("#section #result1").html(data.lastName);
$("#section #result2").html(data.state);
$("#section").slideDown().delay(1000).slideUp();
}
}
});
}
Controller:
[HttpPost]
public userData testGetUser(long userNo)
{
userData result = new userData();
result.firstName = Session["firstName"].ToString();
result.lastName = Session["lastName"].ToString();
result.state = Session["country"].ToString();
result.success = true;
return result;
}