I have a following situation
function Insert(name, parentID) {
$.ajax({
type: "POST",
url: "topic.aspx/Insert",
data: JSON.stringify({
"name": name,
"parentID": undefined
}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
},
error: function (msg) { alert(msg.responseText); }
});
}
And C# looks like this
[WebMethod]
public static int Insert(string name, int? parentID)
{
GM.KnowledgeBase.Business.Topics topics = new GM.KnowledgeBase.Business.Topics();
return topics.Insert(name, parentID);
}
When parentID is null or undefined I get "Invalid web service call, missing value for parameter". Is there a more elegant way to solve this issue other then passing a parameter as a string and detecting if string is empty?