How do I pass null to a nullable parameter of a ASP.NET web service method via javascript
Given the following ASP.NET code:
[System.Web.Script.Services.ScriptService]
public class Quotes : System.Web.Services.WebService
{
[WebMethod]
public void Calculate(int param1, int? param2)
{
开发者_如何转开发
etc.. How can I pass a null value to param2? If I don't pass the parameter at all, or I pass undefined, my error handler fires with "Invalid web service call, missing value for parameter: 'param2'
".
Ok I was being stupid. I simply pass null!
Why is null an object and what's the difference between null and undefined?
If you're using C# 4.0 you could set a default value on the parameter.
ie
[WebMethod]
public void Calculate(int param1, int? param2 = null)
{...}
精彩评论