Calling MVC Actions from Javascript

Suppose we have a very simple action method: it takes no parameters and just returns a string: public string MyTestMethod() { return “Test String”; } What if we would like to call this action method from javascript through Ajax and to display the value it returns? We can do it with jQuery: function AjaxDisplayString() { $.ajax({ url: @Url.Action(“MyTestMethod”), method: ‘GET’, success: function(data) { alert(data); } }); } Not so bad, after all. However, let think, about all implications of the above simple raw approach to the interaction with an action method: Repeating the above code several times in an application … Click here to continue reading.