Skip to content

Instantly share code, notes, and snippets.

@mesuttalebi
Created December 12, 2014 14:08
Show Gist options
  • Save mesuttalebi/c2b098e34ef80827c23c to your computer and use it in GitHub Desktop.
Save mesuttalebi/c2b098e34ef80827c23c to your computer and use it in GitHub Desktop.
Restricting a method to a given submit button, Using ActionMethod Selector to server multi submit form, to behave different for each submit button in Asp.net MVC
public class OnlyIfPostedFromButtonAttribute : ActionMethodSelectorAttribute
{
public string SubmitButton { get; set; }
public override Boolean IsValidForRequest(ControllerContext controllerContext,
MethodInfo methodInfo)
{
// Check if this request is coming through the specified submit button
var o = controllerContext.HttpContext.Request[SubmitButton];
return o != null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment