18

I would like to define a route as follows -

[Route("clients/{*code}/{id:guid}/update")]
public ActionResult Update(string code, Guid id)
{
}

Code will be something like "foo/bar/xyz".

Unfortunately, out-of-the-box MVC doesn't support greedy parameters in the middle of a Route definition.

This has previously been solved using the old MVC routing conventions, however I would like to have this as a RouteAtribute defintion.

jameskind
  • 1,097
  • 2
  • 13
  • 28

2 Answers2

1

As far as I know you cannot do it directly. However, you should be able to use IIS module UrlRewrite and rewrite the query with a greedy parameter in the middle to the one with a greedy parameter at the end.

So a client queries: clients/{*code}/{id:guid}/update and your web api sees clients/{id:guid}/update/{*code}

milanio
  • 4,082
  • 24
  • 34
0

From what I can tell there is no out-of-the-box way of doing this other than to use custom code like this example. Hope it helps.

Voidpaw
  • 910
  • 1
  • 5
  • 18