当我尝试使用MS AJAX PageMethods传递对象时,为什么我的参数为null

时间:2016-08-24 14:58:45

标签: asp.net ajax asp.net-ajax

我也尝试了以下代码段:

PageMethods.MyMethod(JSON.stringify(person), OnMyMethodComplete);

客户端标记:

    </form>
    <script type="text/javascript">
        var person = { firsName: "World" };
        function test() {
            PageMethods.MyMethod(person, OnMyMethodComplete);
        }

        function OnMyMethodComplete(result) { alert(result); }

        window.onload = function () {
            test();
        };
    </script>
</body>
</html>

代码隐藏:

[WebMethod]
public static string MyMethod(Person p)
{
    return "Hello " + p.FirstName;
}

调试: enter image description here

1 个答案:

答案 0 :(得分:0)

我在客户端代码中定义render() { return ( <div> {this.createForm()} </div> ) } ,但在服务器端寻找var Person