【问题标题】:How do I pass null to a nullable parameter of a ASP.NET web service method via javascript如何通过 javascript 将 null 传递给 ASP.NET Web 服务方法的可空参数
【发布时间】:2010-08-24 14:37:42
【问题描述】:

给定以下 ASP.NET 代码:

[System.Web.Script.Services.ScriptService]
public class Quotes : System.Web.Services.WebService
{
    [WebMethod]
    public void Calculate(int param1, int? param2)
    {

等等。如何将空值传递给 param2?如果我根本不传递参数,或者传递 undefined,我的错误处理程序会以 "Invalid web service call, missing value for parameter: 'param2'" 触发。

【问题讨论】:

    标签: javascript asp.net web-services nullable


    【解决方案1】:

    好吧,我是愚蠢的。我只是传递null!

    Why is null an object and what's the difference between null and undefined?

    【讨论】:

      【解决方案2】:

      如果您使用的是 C# 4.0,您可以在参数上设置一个默认值。

      [WebMethod]
          public void Calculate(int param1, int? param2 = null)
          {...}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-07-10
        • 1970-01-01
        • 1970-01-01
        • 2018-01-27
        • 2011-02-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多