mccalltd / AttributeRouting

Define your routes using attributes on actions in ASP.NET MVC and Web API.
http://mccalltd.github.io/AttributeRouting/
MIT License
416 stars 89 forks source link

RestfulRouteConventionAttribute checking ActionNameAttribute #261

Open rahulbpatel opened 11 years ago

rahulbpatel commented 11 years ago

Would it make sense for the RestfulRouteConventionAttribute to check if an action method has the ActionNameAttribute applied to it? I have a scenario where I have multiple submit buttons on a single form for different types of updates. I am using another ActionMethodSelectorAttribute that checks the submit button pressed to pick the appropriate action method. I haven't tested this but was thinking the GetRouteAttributes method could look something like this:

 public override IEnumerable<AttributeRouting.IRouteAttribute> GetRouteAttributes(System.Reflection.MethodInfo actionMethod) {

        // Check if method has an ActionNameAttribute applied to it
        var actionNameAttribute = (ActionNameAttribute) actionMethod.GetCustomAttributes(typeof(ActionNameAttribute), true).FirstOrDefault();
        var methodActionName = (actionNameAttribute == null) ? actionMethod.Name : actionNameAttribute.Name;

        var convention = Conventions.SingleOrDefault(c => c.ActionName == methodActionName);
        if (convention != null)
            yield return BuildRouteAttribute(convention);
 }