ASP.Net MVC, AJAX, and progressive enhancement

By : DAC

I am looking for a reliable technique for adding Ajax to a working ASP.NET MVC application. I want to use jQuery, and understand how to use the AJAX functionality from jQuery.

What I need to know is how I should write my controller so that I can run the site without JavaScript, but at the same time make AJAX calls possible without the need for a separate view, separate controller, or any kind of route hack. My goal is to have a working application enhanced when JavaScript is enabled without the need to duplicate or recreate elements of the app.

By : DAC


in your controller (derived from Controller), you can call Request.IsMvcAjaxRequest() to check if the request is a normal POST or an AJAX request. This will be true if the request was created from a an AjaxForm submit or an AsyncHyperlink. The Ajax form can be made visible by javascript, along with hiding the standard form.

By : Matthew

Typically you would create your site so that it works without JavaScript being enabled. Then you would add the unobtrusive JavaScript needed to enhance your site with Ajax e.g. adding event handlers for links, form submits, etc. to make GET / POST requests and update your UI accordingly.

The only changes you would need in your MVC app would be to handle the Ajax requests and return the data as JSON, XML, etc.

By : Ian Oxley

No, we are no distributing forms or anything with the app... it's an exe. I forgot to mention that the EXE is compressed and obfuscated with KONXIZE 1.0.

By : nmarmol

This video can help you solving your question :)
By: admin