Skip to content

Instantly share code, notes, and snippets.

@jpolvora
Last active December 20, 2015 01:49
Show Gist options
  • Save jpolvora/6051985 to your computer and use it in GitHub Desktop.
Save jpolvora/6051985 to your computer and use it in GitHub Desktop.
public class RequireRouteValuesAttribute : ActionMethodSelectorAttribute {
public string[] ValueNames { get; private set; }
public RequireRouteValuesAttribute(params string[] valueNames) {
ValueNames = valueNames;
}
/// <summary>
/// Check for all strings
/// </summary>
/// <param name="controllerContext"></param>
/// <param name="methodInfo"></param>
/// <returns>Returns true only if all values are found</returns>
public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) {
var contains = false;
foreach (var value in ValueNames) {
contains = controllerContext.Controller.ValueProvider.GetValue(value) != null;
if (!contains) break;
}
return contains;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment