I have the following webmethod on my asp.net code behind page:
[WebMethod(EnableSession = true)]
public static bool SaveFailureData(SimpleFailureData data)
{
}
SimpleFailureData is defined as the following:
public class SimpleFailureData
{
public int Id { get; set; }
public string Comments { get; set; }
public double Score { get; set; }
public double Adjustment { get; set; }
public List<ShutdownData> ShutdownData { get; set; }
}
public class ShutdownData
{
public int Id { get; set; }
public string Description { get; set; }
public bool CausedShutdown { get; set; }
public string ShutdownType { get; set; }
}
What I am trying to figure out is how to call this webmethod and format my data so that it is projected/parsed into that class correctly so I can use it. I tried sending a json string to the method, but my breakpoint inside the method was never hit (so I assume the method failed to call due to improper data format).
This is the JSON I tried sending and then calling the method:
json = JSON.stringify( {
Comments: comments,
Score: score,
Adjustment: seAdjustmentValue,
ShutdownData: breakdowns //this is an array of shutdown objects
});
PageMethods.SaveFailureData(json, function(data) {
return;
});
But this failed to get inside my method. Any tips on what the JSON format should be so that is properly works for passing a class as a parameter?
Here is the JSON I attempted to send to the method:
{
"Comments":"",
"Score":66.66666666666667,
"Adjustment":0,
"ShutdownData":[{"Id":"401","CausedShutdown":true,"ShutdownType":"NORMAL"}]
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…