What you are saying is called javascript generators in the RoR world, and there is no equivalent in the ASP.NET MVC world. Here 's a blog post that illustrates the basics of implementing RJS-like RJS for ASP.NET MVC (the blog uses prototypejs, but can be easily adapted to work with jquery).
Here's another approach using jquery:
public ActionResult Foo()
{
return Json(new { prop1 = "value1", prop2 = "value2" });
}
and consume:
$.getJSON('/home/foo', function(result) {
if (result.prop1 === 'value1') {
alert(result.prop2);
}
});
source
share