2

如何将参数从 javascript 发送到控制器方法?例如我正在尝试发送参数“2012”

这是我视图中的脚本:

$.ajax({
                        type: "get", url: "test", data: {}, // How can i fill this data like @item ?
                        success: function (data) {

                            alert(data);

                        }

我的控制器方法:

public string test()
        {

            TestServices client = new TestServices();
            client.ClientCredentials.UserName.UserName = "service_test";
            client.ClientCredentials.UserName.Password = "..";
            client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;

            decimal? x = client.GetTest(2012, 7, 1);

            return (""+x);


        }
4

1 回答 1

3
[HttpGet]    
public string test(string name, string age)

还有阿贾克斯

$.ajax({
                    type: "get", url: "test", data: {name:"Messi",age:"36yo"}, // How can `i fill this data like @item ?`
                    success: function (data) {

                        alert(data);

                    }
于 2012-09-13T15:18:15.453 回答