Custom Parameter Names With Special Characters in ASP.NET Web API MVC 4

.net, asp.net-mvc, asp.net-web-api, c#, rest

Solution

Use FromUriAttribute

public HttpResponseMessage Get([FromUri(Name = "ms-scale")]int scale, [FromUri(Name = "ms-contrast")]string contrast, [FromUri(Name = "ms-lang")]string lang)

Problem

I have a requirement to create a Get method which takes the following parameter names in the URL: ms-scale ms-contrast ms-lang As you can see, all the names have a dash in them which is not possible in C#. How can I map my method to these parameter names? ``` public HttpResponseMessage Get(int scale, string contrast string lang) ```

Original source

Related problems