Skip to content

Instantly share code, notes, and snippets.

@mesuttalebi
Created December 12, 2014 13:56
Show Gist options
  • Save mesuttalebi/6a2333731f64da3a5218 to your computer and use it in GitHub Desktop.
Save mesuttalebi/6a2333731f64da3a5218 to your computer and use it in GitHub Desktop.
Restricting a method to Ajax calls only, an example of ActionMehodSelector in Asp.net MVC, If request is an ajax request, it will be served by action method, Else It will not.
public class AjaxOnlyAttribute : ActionMethodSelectorAttribute
{
public override Boolean IsValidForRequest(
ControllerContext controllerContext, MethodInfo methodInfo)
{
return controllerContext.HttpContext.Request.IsAjaxRequest();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment