Skip to content

Instantly share code, notes, and snippets.

@chrishasz
Created September 30, 2013 17:51
Show Gist options
  • Select an option

  • Save chrishasz/6767497 to your computer and use it in GitHub Desktop.

Select an option

Save chrishasz/6767497 to your computer and use it in GitHub Desktop.
ASP.NET MVC AjaxOnly Decoration for Controller Actions. Pair with ReturnPartial() for clean, request-controlled partial markup. Usage: [AjaxOnly] public ActionResult Action( ... ) { return PartialView(); }
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