Ever wanted to restrict actions to only responding to Ajax requests?  How about restricting them through the use of a custom attribute?

You can do this through using the code below:

The attribute simply returns true or false depending on if the request was generated through an Ajax call (i.e. “XmlHttpRequest” is in the request header).

Then to use the code, annotate your controller’s action like so: