Skip to content

Instantly share code, notes, and snippets.

@cdeutsch
Created September 25, 2013 21:39
Show Gist options
  • Select an option

  • Save cdeutsch/6706448 to your computer and use it in GitHub Desktop.

Select an option

Save cdeutsch/6706448 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.Mvc.Html;
using System.Collections;
using System.Linq.Expressions;
using System.Web.Routing;
using System.Reflection;
namespace System.Web.Mvc
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class MultipleButtonAttribute : ActionNameSelectorAttribute
{
public string Name { get; set; }
public string Argument { get; set; }
public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
{
bool isValidName = false;
string keyValue = string.Format("{0}:{1}", Name, Argument);
var value = controllerContext.Controller.ValueProvider.GetValue(keyValue);
if (value != null)
{
controllerContext.Controller.ControllerContext.RouteData.Values[Name] = Argument;
isValidName = true;
}
return isValidName;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment