AttributeRouting icon indicating copy to clipboard operation
AttributeRouting copied to clipboard

Auto create routes for ChildActionOnlyAttribute actions?

Open paultyng opened this issue 12 years ago • 3 comments

Just thought this may be a time saver for some people.

I have plenty of action methods that are only used internally with an Html.Action and are marked [ChildActionOnly].

I have to make throw away routes for these just so they render, it may be useful to just automatically create these routes off the attributes to avoid wasted code.

I'd be willing to take a crack at a pull for this if there is any interest.

paultyng avatar Dec 14 '12 20:12 paultyng

Couldn't you also just:

  1. Add a standard route that is used for your child actions. Could have some code that works a constraint against this route so that only child actions are matched. Could also use constraint to prevent matching inbound routes while matching outbound routes. PROS - only one additional route in your route table.
  2. Create a custom route convention that yields routes for actions marked with [ChildActionOnly]. Apply this convention on a base controller.

Regardless of what you do, you could contribute the result to AR:

  • If a standard route, you could create a property on AttributeRouting.Web.Mvc.AttributeRoutingConfiguration that turns on this support. Then, when generating routes, if this feature is exposed, add the standard route to the route table.
  • If a convention, I'd put that in AttributeRouting.Web.Mvc.
  • If something else, let me know and I can point you in the right direction regarding the code.

Cheers. Love issues with an offer of implementation, btw. :)

mccalltd avatar Dec 14 '12 21:12 mccalltd

Hey Paul,

Still want to do this? What did you come up with? Just read over the issue again and think a default/vanilla route in the route table would lowest hanging and work just fine. If you've cooled to the idea I'm going to close the issue.

Cheers!

mccalltd avatar Feb 14 '13 18:02 mccalltd

Wanted to chime in and also say I've run into this... although I'm OK with adding non-functional routes, it would be nice to have these just ignored.

kamranayub avatar Feb 28 '13 21:02 kamranayub