Reputation: 18343
How to pass "NULL" value into nullable field during call from JavaScript to ASP.NET WebService?
I call method in the following way from JavaScript:
ws_data.SaveTasks(eval({"MyValue":"null"}), OnSaveComplete, OnError, OnTimeOut);
When I do, I receive an error (framework calls OnError):
null is not a valid value for Int32
If instead of "null" I pass valid integer - everything works fine.
Please advise: What I do wrong? How to pass 'null' value which will be 'translated' into a NULL .NET object?
Any ideas are welcome!
P.S. Here are some details.
Declaration of essential part of MyData:
public class MyData
{
...
public int? MyValue { get; set; }
}
Declaration of ASP.NET web service:
[WebService(Namespace = "...")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class ws_data : WebService
{
[WebMethod(true)]
public object SaveData(MyData data)
{...}
}
And ws_data is declared via ScriptManager:
<asp:ScriptManager runat="server">
<Services>
<asp:ServiceReference Path="/ws_data.asmx" />
</Services>
</asp:ScriptManager>
Upvotes: 0
Views: 3424
Reputation: 25743
This is because you're passing the string null instead of the non-value null. Remove the quotes to make it an actual null.
{"MyValue": null}
I'm not sure about your eval
either, I think it can be omitted as eval
is supposed to take a string an interpret it as JavaScript.
ws_data.SaveTasks({"MyValue": null}, OnSaveComplete, OnError, OnTimeOut);
Upvotes: 1