纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
634 B

3 years ago
  1. using System;
  2. using System.Web.Mvc;
  3. namespace NFine.Web
  4. {
  5. [AttributeUsage(AttributeTargets.Method)]
  6. public class HandlerAjaxOnlyAttribute : ActionMethodSelectorAttribute
  7. {
  8. public bool Ignore { get; set; }
  9. public HandlerAjaxOnlyAttribute(bool ignore = false)
  10. {
  11. Ignore = ignore;
  12. }
  13. public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo)
  14. {
  15. if (Ignore)
  16. return true;
  17. return controllerContext.RequestContext.HttpContext.Request.IsAjaxRequest();
  18. }
  19. }
  20. }