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?
+2
A:
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.
çağdaş
2009-04-10 11:41:37