Dave New
Dave New

Reputation: 40092

The route template cannot start with a '/' or > '~' character and it cannot contain a '?' character

I am getting the an exception with the following route attribute:

[Route("{id}?action=decline")]

Exception:

An exception of type 'System.ArgumentException' occurred in System.Web.Http.dll but was not handled in user code

Additional information: The route template cannot start with a '/' or '~' character and it cannot contain a '?' character.

Why is this not allowed?

Upvotes: 9

Views: 21670

Answers (2)

Ray Cheng
Ray Cheng

Reputation: 12586

you can do this and you'll have access to both id and action:

[Route("{id}")]

public IHttpActionResult YourMethod([FromUri] string action)

Upvotes: 3

Stefan Ossendorf
Stefan Ossendorf

Reputation: 801

I think this isn't allowed, because a query string is not part of a URI-Path. (See RFC3986 Section 3.3 Path , it doesn't include the query part)
But I have no hard fact to prove that :/. Perhaps these links help you:

Routing based on query string parameter name
QueryString with MVC 5 AttributeRouting in Web API 2
Attribute Routing in ASP.NET Web API 2

Upvotes: 4

Related Questions