2

How can I send parameter from javascript to controller method ? For example I 'm trying to send parameter "2012"

Here is my script in my View:

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

                            alert(data);

                        }

my controller method:

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);


        }
1
  • could you show me a simple example ? @Magrangs Commented Sep 13, 2012 at 15:02

1 Answer 1

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

And the ajax

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

                        alert(data);

                    }
Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much for example how can I send model paremeter data: {@model.id} ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.