How to call a controller action by jQuery

With jQuery you are able to invoke an action of a Asp .Net MVC application’s controller.
This is the code you need:

You can establish the request type (GET, SET and so), whether the request should be asynchronous or not (parameter async true or false), whether the request should be cached or not (parameter cache), a Javascript function to be called in case of success of the server request (parameter success) or in case of request fails (parameter error).
The parameter “data” of the function called in case of success contains the return value by the server call.

However there are many others useful parameters you can use. For a complete list go here. It’s also possible to make the same call but with a Json return value by the $.getJSON funtion.

Link utili della settimana

  1. Descrizione di Unity, il framework di Inversion of Control e Dipendency Injection sviluppato dal team di P&P (qui è presente la versione 1.2 per Silverlight)
  2. 45 passi per diventare agili
  3. xVal, libreria per la validazione client side di applicazioni ASP .NET MVC
  4. Anti XSS Library ver. 3.1
  5. CodePad .NET 1.0 Beta 2, un editor leggero per provare spezzoni di codice
  6. Strongly typed session variables in ASP .NET MVC
  7. Visual Studio 2010 e .NET Framework 4.0 Training Kit – May preview