AttributeRouting
AttributeRouting copied to clipboard
Ajax Routes?
I don't know if it's a good idea but I would find useful to be able to dispatch a request to a given action based on Request.IsAjaxRequest()
. Something like:
[GET("some/url")]
public ActionResult SomeAction() { ... }
[GET("some/url", Ajax = true)]
public ActionResult SomeActionAjax() { ... }
What do you think?
Interesting.... Should be simple to do via a route constraint that is added if the Ajax flag is true. In your example, though, you'd have to have your ajax route first, cause I want routes to respond to both ajax/non by default.
Ah, of course. So do you mean setting the ActionPrecedence or moving the second route "physically" in the code? (I didn't know the order in which routes appear would matter... if you extract the routes via reflection, wouldn't they be retrieved alphabetically ordered?)
Yep. So they are retrieved in the order declared. You can override that within a controller using the ControllerPrecedence property (if you can't or don't want to reorder). ActionPrecedence would have no affect, cause there's only a single route on each action. But anywho it would be a pretty straightforward thing to implement if you'd like to. Otherwise I can get to it soonish....
Just had a look to see if I could do it myself but I am not sure what do to with the abstraction layer dealing with the web-hosted / self-hosted scenarios, (how to access the Request object?)
I would rather leave it to you if you don't mind :-) (nothing urgent)