Created
December 12, 2014 13:56
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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