AttributeRouting
AttributeRouting copied to clipboard
Auto create routes for ChildActionOnlyAttribute actions?
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.
Couldn't you also just:
- 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.
- 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.AttributeRoutingConfigurationthat 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. :)
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!
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.