2

I am making a jquery ajax call to an mvc controller. I want to return 2 or more variables from the controller. How do I package data in controller for this ? how do I extract with jquery?

1 Answer 1

4

In your controller action, use the built in Json method :

return Json(new {name1 = "value1", name2 = "value2"});

And your jQuery call :

$.ajax({
    type: "POST",
    url: "/your-url",
    dataType: "json",
    data: {data: to_send},
    success: function(msg) {
       alert(msg.name1);
       alert(msg.name2);
    }
});
//you can of course use another ajax function jQuery provides.
Sign up to request clarification or add additional context in comments.

Comments

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.